mercredi 15 juillet 2015

Can't Edit Item -

Im using Simple Form gem.

When I try to update item with INVALID Data for instancing missing out some information like the Price. Rails is suppose to redirect to the edit view. As you can see by the controller.

  def update
    @item = Item.find(params[:id])
    if @item.update(item_params)
       redirect_to @item
       flash[:success] = 'Item was successfully updated.'
    else
      flash[:danger] = "Item didn't update"
      render "edit"
    end
  end

However it doesn't. I just get this error.

Showing

/Users/josep/Documents/Safsy/Website/Safsy/Safsy/app/views/shared/_error_messages.html.erb where line #1 raised:

undefined method `errors' for nil:NilClass

<% if @user.errors.any? %>
  <div id="error_explanation">
    <div class="alert alert-danger">
      The form contains <%= pluralize(@user.errors.count, "error") %>.
    </div>
    <ul>

Below is _error.messages.html.erb

<% if @user.errors.any? %>
  <div id="error_explanation">
    <div class="alert alert-danger">
      The form contains <%= pluralize(@user.errors.count, "error") %>.
    </div>
    <ul>
    <% @user.errors.full_messages.each do |msg| %>
      <li><%= msg %></li>
    <% end %>
    </ul>
  </div>
<% end %>

Thanks for any help in advance

Aucun commentaire:

Enregistrer un commentaire