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