我需要设置属性,在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|