我正在使用带有 Decent_exposure、Strong_parameters 的 Simple_form 我有以下设置,我可以发布给家庭,但没有任何东西发布给邻居
模型
class Household < ActiveRecord::Base
include ActiveModel::ForbiddenAttributesProtection
has_many :neighbors
accepts_nested_attributes_for :neighbors
看法
= simple_nested_form_for household do |f|
= f.input :household_name
= f.simple_fields_for :neighbor, Neighbor.new do |neighbor_form|
= neighbor_form.input :first_name
= neighbor_form.input :middle_name
= neighbor_form.input :last_name
= neighbor_form.input :address
= f.button :submit
根据我的日志中的以下内容,看起来表单正在工作,但它没有将嵌套模型保存到邻居 - 我已经尝试了 simple_fields_for :neighbor do 和 simple_fields_for :neighbor, Neighbor.new 希望创建一个新邻居会有所帮助但事实并非如此。
Parameters:{"utf8"=>"✓",
authenticity_token"=>"cVTteqPFa0JMoFi/ys0wAmNIQghubADv5lbPBr6hyq0=",
"household"=> {"household_name"=>"Deew", "neighbor"=>{"first_name"=>"Bill",
"middle_name"=>"", "last_name"=>"Ew", "street"=>"we"}}, "commit"=>"Create Household"}
(0.1ms) begin transactionSQL (0.7ms) INSERT INTO "households" ("created_at",
"household_name", "name", "updated_at") VALUES (?, ?, ?, ?)
[["created_at", Sun, 03 Feb 2013 03:02:56 UTC +00:00], ["household_name", "Deew"],
["name", nil], ["updated_at", Sun, 03 Feb 2013 03:02:56 UTC +00:00]](0.8ms)
commit transaction