0
我想將一些自定義問題添加到表單底部。然而,問題的id不與答案字段相關聯。我會怎麼做呢?Rails fields_for fields_for不與父級ID關聯的行
input.html.erb
<% @event.event_questions.each do |question| %>
<%= f.simple_fields_for :event_question, question do |answer| %>
<%= answer.simple_fields_for :event_answer do |e| %>
<%= e.input :answer, label: question.question %>
<% end %>
<% end %>
<% end %>
output.html
<div class="form-group string required participant_event_question_event_answer_answer"><label class="string required control-label" for="participant_event_question_event_answer_answer"><abbr title="required">*</abbr> Goals</label><input class="string required form-control" type="text" name="participant[event_question][event_answer][answer]" id="participant_event_question_event_answer_answer" /></div>
<div class="form-group string required participant_event_question_event_answer_answer"><label class="string required control-label" for="participant_event_question_event_answer_answer"><abbr title="required">*</abbr> Action Plan</label><input class="string required form-control" type="text" name="participant[event_question][event_answer][answer]" id="participant_event_question_event_answer_answer" /></div>
<div class="form-group string required participant_event_question_event_answer_answer"><label class="string required control-label" for="participant_event_question_event_answer_answer"><abbr title="required">*</abbr> Vision</label><input class="string required form-control" type="text" name="participant[event_question][event_answer][answer]" id="participant_event_question_event_answer_answer" /></div>
這是答案的一部分。 – Coder2000
將父母ID作爲表單輸入安全嗎?偷偷摸摸的用戶可能會改變它,從而編輯另一個問題的答案。 – mlt