1

私はnested_formgemを使用しており、次の形式を持っています:

= simple_nested_form_for @profile do |f|
  = f.fields_for :person do |p|
    = p.fields_for :web_profiles do |e|
      = e.input :name
      = e.input :url
      = e.link_to_remove 'Remove'
    = p.link_to_add 'Add Web Profile', :web_profiles

Person
  has_many :web_profiles
  has_one :profile
Profile
  belongs_to :person
WebProfile
  belongs_to :person

フォームは正しく生成されますが、2 つ目以降の Web プロファイルを追加しようとすると、フォームを送信した後、データベースに最後の Web プロファイルしか表示されません。

Started POST "/profiles" for 127.0.0.1 at 2013-06-17 14:45:48 +0200
Processing by ProfilesController#create as HTML
  Parameters: {"utf8"=>"✓", "authenticity_token"=>"x2EEQXF9Blnvp0Ib1HG9XjHtaCEHwCNaBzPnZwxnlbI=", "profile"=>{"person_attributes"=>{"gender"=>"", "title"=>"", "first_name"=>"Darek", "last_name"=>"", "birthday"=>"", "place_of_birth"=>"", "company_id"=>"", "web_profiles_attributes"=>{"1371473134262"=>{"name"=>"zzzz", "url"=>"aaaa.pl", "_destroy"=>"false"}}}, "available_at"=>"", "last_contact_at"=>"", "remind_at"=>"", "blacklisted"=>"0", "overall_rating"=>""}, "commit"=>"Create Profile"}
Redirected to http://0.0.0.0:3000/profiles/2
Completed 302 Found in 18ms (ActiveRecord: 1.1ms)

これは、2 つの Web プロファイルを追加した後のログですが、パラメータにweb_profiles_attributesは 1 つの Web プロファイル オブジェクトしか表示されません。

4

1 に答える 1