加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

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

在控制器中

params.require(:store).permit(:store).permit!

字段显示,但是当我提交表单时,它没有意义,商店关联是空的.问题怎么解决?

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|

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读