tomekfranek
tomekfranek

Reputation: 7099

Can't save more that one object using nested form?

I am using nested_form gem and have following form:

= 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

Forms are generated correctly but when I am trying to add second and more web profile, after submitting form I see only last web profile in database.

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)

This is log after I added two web profiles but in parameters for web_profiles_attributes I see only one web profile object.

Upvotes: 1

Views: 75

Answers (1)

tomekfranek
tomekfranek

Reputation: 7099

Recently gem was updated and problem stopped occurs.

https://github.com/ryanb/nested_form/issues/271

Upvotes: 1

Related Questions