mercredi 15 février 2017

rails undefined method `[]' for nil:NilClass on association

After place a association images right after save the product, rails spitting out about method `[]' for nil:NilClass, why is showing nil, for a association already made?

  def create

  @product = current_square.products.build(params[:product])
 @images = @product.images.build
    respond_to do |format|
     format.html do
        if @product.save

params[:images]['ifoto'].each do |a|
          @images = @product.images.create!(:ifoto => a)
      end

       end
end

Aucun commentaire:

Enregistrer un commentaire