0

Sorry for noob question, I'm just trying RoR, but I have an issue with passing to strong params (I guess) nested resources items.

controller:

  def update
    if @product.update(product_params)
      redirect_to @product, notice: "product has been updated"
    end
  end

models:

class Image < ActiveRecord::Base
  belongs_to :products
end

class Product < ActiveRecord::Base
  has_one :image, dependent: :destroy
  accepts_nested_attributes_for :image
end

view:

= p.fields_for :image do |img|
      = img.text_field :path

params:

"image_attributes"=>{"path"=>"1.jpg", "id"=>"13"},
   "category_id"=>"2"}

As result only image path not updating...

Please give me solution. Thank You!

sjstrutt
  • 5,625
  • 6
  • 25
  • 21
  • Add this to product_params: `params.require(:product).permit(:category_id , image_attributes: [:path, :id])` – cristian Apr 02 '15 at 22:10
  • but i have: 'def product_params params.require(:product).permit(:title, :description, :price, :sku, :category_id, image_attributes: [:path, :id]) end' – Severynsky Apr 03 '15 at 08:15

0 Answers0