title: Can't edit: undefined method `map' for nil:NilClass
body: <p>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.</p>
  
  <p>Error when i try to edit.</p>
  
  <pre><code>Completed 500 Internal Server Error in 16ms
  
  ActionView::Template::Error (undefined method `map' for nil:NilClass):
      17:
      18:             &lt;p&gt;&lt;%= f.link_to_add "Add a image", :product_images, :data =&gt; { :product_image =&gt; "#product_images" } %&gt;&lt;/p&gt;
      19:
      20:             &lt;%= f.collection_select :category_id, @categories, :id, :name, include_blank: true, prompt: "Select One Category" %&gt;
      21:
      22:             &lt;% @categories.each do |category| %&gt;
      23:               &lt;div class='sizes_container' id 
  </code></pre>
  
  <p>Here is the Product form. </p>
  
  <pre><code>&lt;%= javascript_include_tag "custom" %&gt;
  &lt;div class="container"&gt;
    &lt;div class=“row”&gt;
      &lt;div class="col-md-6 col-md-offset-3"&gt;
        &lt;div class="panel panel-primary"&gt;
          &lt;div class="panel-body"&gt;
            &lt;%= simple_nested_form_for @product do |f| %&gt;
  
              &lt;%= f.fields_for :product_images do |product_image| %&gt;
                &lt;% if product_image.object.new_record? %&gt;
                  &lt;%= product_image.file_field(:product_image) %&gt;
                  &lt;%= product_image.link_to_remove "Remove Image", data: { confirm: "Are you sure you want to delete this image?" } %&gt;
                &lt;% else %&gt;
                  &lt;%= product_image.hidden_field :_destroy %&gt;
                &lt;% end %&gt;
              &lt;% end %&gt;
  
              &lt;p&gt;&lt;%= f.link_to_add "Add a image", :product_images, :data =&gt; { :product_image =&gt; "#product_images" } %&gt;&lt;/p&gt;
  
              &lt;%= f.collection_select :category_id, @categories, :id, :name, include_blank: true, prompt: "Select One Category" %&gt;
  
              &lt;% @categories.each do |category| %&gt;
                &lt;div class='sizes_container' id ='sizes_container_for_&lt;%= category.id %&gt;'&gt;
                  &lt;% category.sizes.each do |size| %&gt;
                    &lt;%= label_tag size.title %&gt;
                    &lt;%= f.simple_fields_for :product_sizes do |product_size| %&gt;
                      &lt;%= product_size.input :quantity %&gt;
                      &lt;%= product_size.hidden_field :size_id %&gt;
                    &lt;% end %&gt;
                  &lt;% end %&gt;
                &lt;/div&gt;
              &lt;% end %&gt;
  
              &lt;%= f.input :title, label:"Title"%&gt;
              &lt;%= f.input :price, label:"Price"%&gt;
              &lt;%= f.input :description,label:"Description" %&gt;
              &lt;%= f.input :size_description, label:"Size Details"%&gt;
              &lt;%= f.input :shipping_description, label:"Shipping Details"%&gt;
              &lt;%= f.input :tag_list,label:"Tags - Seperate tags using comma ','. 5 tags allowed per product" %&gt;
              &lt;%= f.button :submit, "Create new product", class: "btn-lg btn-success" %&gt;
            &lt;% end %&gt;
          &lt;/div&gt;
        &lt;/div&gt;
      &lt;/div&gt;
    &lt;/div&gt;
  &lt;/div&gt;
  </code></pre>
  
  <p>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.</p>
  
  <p>Products controller</p>
  
  <pre><code>class ProductsController &lt; ApplicationController
    before_action :set_product, only: [:edit, :show, :update]
    before_action :correct_user_edit, only: [:edit, :update, :destroy]
    before_action :logged_in_user, only: [:new, :edit, :update, :destroy]
  
    def index
      @products = Product.all
    end
  
    def new
      @product = Product.new
      @categories = Category.preload(:sizes).order(:name)
      @product.product_images.build
      @product.product_sizes.build
    end
  
    def home
      @products = Product.paginate(page: params[:page])
    end
  
    def edit
    end
  
    def show
    end
  
    def update
      if @product.update(product_params)
         redirect_to @product
         flash[:success] = 'Item was successfully updated.'
      else
        render "edit"
      end
    end
  
    def create
      @product = Product.new product_params
      @product.user_id = current_user.id
      if @product.save
        redirect_to @product
        flash[:success] = "You have created a new product"
      else
        flash[:danger] = "Your product didn't save"
        render "new"
      end
    end
  
    def destroy
      @product.destroy
      flash[:success] = "Product deleted"
      redirect_to user_products_path
    end
  
    def add_outfit_products
      @products = current_user.products
    end
  
    def add_outfit_similar_products
      @products = current_user.products
    end
  
    private
  
    def create_product_images
      params["product"]["product_images_attributes"].each do |index, image|
        ProductImage.create(product_image: image, product_id: @form.product.id)
      end
    end
  
    def set_product
      @product = Product.find(params[:id])
    end
  
    def product_params
       params.require(:product).permit(
        :title,
        :price,
        :description,
        :tag_list,
        :category_id,
        :size_description,
        :shipping_description,
        product_images_attributes: [:product_image, :_destroy],
        product_sizes_attributes: [:size_id, :quantity]
      )
    end
  
    def correct_user_edit
      if @product = current_user.products.find_by(id: params[:id])
      else
        redirect_to root_url if @product.nil?
      end
    end
  end
  </code></pre>