jeudi 24 mai 2018

else statement not working in controller

i am using a simple if else statement in my controller and my else statement is not working. And I don't know where my error is.

Controller code

def update
    authorize! :update, @user
    respond_to do |format|
      if @user.update(user_params)
        format.html { redirect_to users_path, notice: "#{@user.email} was successfully #{helpers.user_active(@user.active)}." }
      else
        p'*************************'
        format.html { render :index }
      end
    end
  end

  private

  def set_user
    @user = User.find(params[:id])
  end

  def user_params
    params.permit(:active)
  end

view code

<% @users.each do |user| %>
  <td>
    <%= button_to block_button(user.active), user_path(id: user.id, active: !user.active),  class: block_color(user.active),  method:  :patch  %>
  </td>
<% end %>

I found that my else condition is not working while writing Rspec code. Can anyone help me fix it? Thank you in advance

Aucun commentaire:

Enregistrer un commentaire