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

表单生成正确,但是当我尝试添加第二个和更多网络配置文件时,在提交表单后我只看到数据库中的最后一个网络配置文件。

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 配置文件后的日志,但在参数中web_profiles_attributes我只看到一个 Web 配置文件对象。

4

1 回答 1

1

最近 gem 被更新并且问题停止发生。

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

于 2013-06-18T10:03:27.950 回答