ネストされたフォームにいくつかのフィールドを追加しようとしています。宝石を含めましたnested_forms
( https://github.com/ryanb/nested_form )。
私の作成済みマップでは問題なく動作しますが、新しいフィールドを追加できません。
私のコントローラー:
def new
@people = Person.all
@vehicles = Vehicle.all
@roles = Role.all
@pratice_people = []
@people.each do |a|
if a.at1 == true
@pratice_people << a
end
end
@practice = Practice.new
@pratice_people.count.times { @practice.uebung_maps.build }
render action: "new"
end
そして私のフォーム:
<% @runs = 0 %>
<%= f.fields_for :uebung_maps do |map| %>
<tr>
<%= map.hidden_field :role_id, :id => "role_id_#{@runs}" %>
<%= map.hidden_field :vehicle_id, :id => "vehicle_id_#{@runs}" %>
<%= map.hidden_field :person_id , :value => @pratice_people[@runs].id %><br/>
<td><%= @pratice_people[@runs].name %></td>
<td><%= map.select :role_id, options_from_collection_for_select(@roles, :id, :name), :include_blank => true %></td>
<td><%= map.select :vehicle_id, options_from_collection_for_select(@vehicles, :id, :name), :include_blank => true %></td>
<td><%= map.text_field :time %></td>
</tr>
<% @runs += 1 %>
<% end %>
<%= f.link_to_add "+" , :uebung_maps %>
ページにアクセスしようとすると、次のエラーレポートが表示されます
Called id for nil, which would mistakenly be 4 -- if you really wanted the id of nil, use object_id
再実行するロジックを作成する必要がありますか (またはその方法)は、 gemPractice.uebung_maps.build?
内で行われると思っていたので....nested_forms