如何在rails form_for中显示数组中的每个对象

时间:2016-10-06 12:52:29

标签: ruby-on-rails ruby form-for

<%=form_for @question do |f|%>

  <%=f.label :name, "Question:"%>
  <%=f.text_field :name%>

  <%=f.label :answer, "Answer:"%>
  <%=f.text_field :answer%>

  <%=f.label :wrong_answers%>
  <%=f.text_field :wrong_answers, multiple: true%>

  <%=f.label :wrong_answers%>
  <%=f.text_field :wrong_answers, multiple: true%>

  <%=f.label :wrong_answers%>
  <%=f.text_field :wrong_answers, multiple: true%>
<%end%>

当我创建这样的问题时,

Question.create(
  name: "1+1?",
  answer: "2",
  wrong_answers: ["1", "4", "3"])

编辑表单将每个wrong_answer文本字段显示为[&#34; 1&#34;,&#34; 4&#34;,&#34; 3&#34;]。我的问题是如何让它在不同的文本字段中显示每个数字。

1 个答案:

答案 0 :(得分:0)

试试这个:

/oranghrm/installation/path/symfony/logs

相反:

<% @question.wrong_answers.each do |wa| %>
   <%= text_field_tag "question[wrong_answers][]",  wa %>
<% end %>