使用嵌套表单无法保存更多的那个对象?

时间:2013-06-17 13:47:35

标签: ruby-on-rails ruby ruby-on-rails-3 nested-forms

我正在使用nested_form gem,并有以下表格:

= 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

表单是正确生成的,但当我尝试添加第二个和更多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)

这是我添加两个网络配置文件后的日志,但在web_profiles_attributes的参数中我只看到一个网络配置文件对象。

1 个答案:

答案 0 :(得分:1)

最近宝石已更新并且问题已停止。

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