0
插槽有很多學生
我的形式:Rails的表單輔助意外PARAMS哈希
<%= form_for(@slot) do |f| %>
<% @slot.students.each do |student| %>
<%= f.fields_for student, index: student.id do |student_form| %>
ID: <%= student.id %>
Present: <%= student_form.check_box :present %><br>
<% end %>
<% end %>
<div class="actions">
<%= f.submit %>
</div>
<% end %>
和槽控制器得到這個PARAMS哈希:
"slot"=>{
"student"=>{"1"=>{"present"=>"0"},
"2"=>{"present"=>"0"},
"3"=>{"present"=>"0"},
"4"=>{"present"=>"0"},
"5"=>{"present"=>"0"},
"commit"=>"Update Slot",
"id"=>"125251"}
因爲我需要學生的ID,但我不知道知道我怎樣才能通過每個學生。這種方式對我來說更容易:
"slot"=>{
"student"=>{{"id"=>"1","present"=>"0"},
{"id"=>"2","present"=>"0"},
{"id"=>"3","present"=>"0"},
{"id"=>"4","present"=>"0"},
{"id"=>"5","present"=>"0"},
"commit"=>"Update Slot",
"id"=>"125251"}
我該如何編輯表格?非常感謝。