我正在尝试在表单底部添加一些自定义问题。但是,问题的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>
答案 0 :(得分:0)
假设question_id
表中有answers
,您可以尝试以下代码。
<% @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 %>
<%= e.input :question_id, as: :hidden, input_html: { :value => question.id }
<% end %>
<% end %>
<% end %>