对不起noob问题,我只是尝试RoR,但是我有一个问题,即传递给强大的params(我猜)嵌套资源项。
控制器:
def update
if @product.update(product_params)
redirect_to @product, notice: "product has been updated"
end
end
模型:
class Image < ActiveRecord::Base
belongs_to :products
end
class Product < ActiveRecord::Base
has_one :image, dependent: :destroy
accepts_nested_attributes_for :image
end
视图:
= p.fields_for :image do |img|
= img.text_field :path
params:
"image_attributes"=>{"path"=>"1.jpg", "id"=>"13"},
"category_id"=>"2"}
结果只有图像路径没有更新...
请给我解决方案。 谢谢!