【发布时间】:2014-01-08 11:32:26
【问题描述】:
我需要为在新建和编辑操作中有一个关联设置属性,所以我有这个:
产品型号
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"}
【问题讨论】:
标签: ruby-on-rails ruby-on-rails-3