jeudi 14 janvier 2016

Can't edit: undefined method `map' for nil:NilClass

Hello after creating a Product i can't edit it. The form a little complex so its made it i hard to get the edit to work.

Error when i try to edit.

Completed 500 Internal Server Error in 16ms

ActionView::Template::Error (undefined method `map' for nil:NilClass):
    17:
    18:             <p><%= f.link_to_add "Add a image", :product_images, :data => { :product_image => "#product_images" } %></p>
    19:
    20:             <%= f.collection_select :category_id, @categories, :id, :name, include_blank: true, prompt: "Select One Category" %>
    21:
    22:             <% @categories.each do |category| %>
    23:               <div class='sizes_container' id 

Here is the Product form.

<%= javascript_include_tag "custom" %>
<div class="container">
  <div class=“row”>
    <div class="col-md-6 col-md-offset-3">
      <div class="panel panel-primary">
        <div class="panel-body">
          <%= simple_nested_form_for @product do |f| %>

            <%= f.fields_for :product_images do |product_image| %>
              <% if product_image.object.new_record? %>
                <%= product_image.file_field(:product_image) %>
                <%= product_image.link_to_remove "Remove Image", data: { confirm: "Are you sure you want to delete this image?" } %>
              <% else %>
                <%= product_image.hidden_field :_destroy %>
              <% end %>
            <% end %>

            <p><%= f.link_to_add "Add a image", :product_images, :data => { :product_image => "#product_images" } %></p>

            <%= f.collection_select :category_id, @categories, :id, :name, include_blank: true, prompt: "Select One Category" %>

            <% @categories.each do |category| %>
              <div class='sizes_container' id ='sizes_container_for_<%= category.id %>'>
                <% category.sizes.each do |size| %>
                  <%= label_tag size.title %>
                  <%= f.simple_fields_for :product_sizes do |product_size| %>
                    <%= product_size.input :quantity %>
                    <%= product_size.hidden_field :size_id %>
                  <% end %>
                <% end %>
              </div>
            <% end %>

            <%= f.input :title, label:"Title"%>
            <%= f.input :price, label:"Price"%>
            <%= f.input :description,label:"Description" %>
            <%= f.input :size_description, label:"Size Details"%>
            <%= f.input :shipping_description, label:"Shipping Details"%>
            <%= f.input :tag_list,label:"Tags - Seperate tags using comma ','. 5 tags allowed per product" %>
            <%= f.button :submit, "Create new product", class: "btn-lg btn-success" %>
          <% end %>
        </div>
      </div>
    </div>
  </div>
</div>

Any ideas? I had a look around the net i couldn't find the answer. So any help would be great. Thank you in advance.

Aucun commentaire:

Enregistrer un commentaire