ruby-on-rails – has_one关联的嵌套属性
发布时间:2020-12-16 19:29:18 所属栏目:百科 来源:网络整理
导读:我需要设置属性,在new和edit动作中有一个关联,所以我有这个: 产品型号 has_one :storeaccepts_nested_attributes_for :store 形成 = form_tag @product do |f| = f.fields_for :store do |store_fields| = render 'store_form',:f = store_fields 在控制器
我需要设置属性,在new和edit动作中有一个关联,所以我有这个:
产品型号 has_one :store accepts_nested_attributes_for :store 形成 = form_tag @product do |f| = f.fields_for :store do |store_fields| = render 'store_form',:f => store_fields 在控制器中
字段显示,但是当我提交表单时,它没有意义,商店关联是空的.问题怎么解决? UPD params.require(:product).permit(store_attributes: [:store_id,:supplier_id,:margin,:discount]).permit! 日志: Parameters: {"utf8"=>"?","authenticity_token"=>"...","product"=>{"name"=>"qwefqwefasdf","description"=>"","permalink"=>"asdf","store_attributes"=>{"margin"=>"123","discount"=>"123"}},"button"=>"","id"=>"asdf"} 解决方法
好的,正确的答案是
更改 = f.fields_for :store do |store_fields| 至 = f.fields_for :store,@vendor.store do |store_fields| (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |