嵌套属性不适用于Simple_form,Decent_exposure,Strong_parameters

时间:2013-02-03 03:17:41

标签: ruby-on-rails simple-form

我正在使用带有Decent_exposure的Simple_form,Strong_parameters我有以下设置,我可以发布到家庭但没有任何内容发布给邻居

模型

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

1 个答案:

答案 0 :(得分:0)

确保在允许的参数中包含neighbors_attributes。