工作這是我nested_form:Nested_form寶石不使用Rails 4
..
...
54 <div>
55 <h2> Address </h2>
56 <%= f.fields_for :address do |address_form| %>
57 <%= address_form.text_field :country %>
58 <% end %>
59 </div>
60
61 <div>
62 <h2> Participants </h2>
63 <%= f.fields_for :participants do |participant_form| %>
64 <%= participant_form.text_field :name %>
65 <%= participant_form.link_to_remove "Remove this participant" %>
66 <% end %>
67 <p><%= f.link_to_add "Add a participant", :participants %></p>
68 </div>
...
..
現在,當我訪問我的模型/新頁面不渲染的地址或參與任何領域。
這是我的模型:
1 class CompetitionEntry < ActiveRecord::Base
2 has_many :participants
3 has_one :address
4 has_many :music_programs
5
6 accepts_nested_attributes_for :address
7
8 accepts_nested_attributes_for :participants, :music_programs,
9 :allow_destroy => true,
10 :reject_if => :all_blank
11 end
這是我的控制器:
16 def new
17 @competition_entry = CompetitionEntry.new
18 end
爲什麼會發生?我錯過了什麼?
難道是它試圖渲染的,在一個新的記錄,也有現有的參與者沒有? – lime