我想为来自fields_for的div设置一个id,我编写了以下代码,但它不起作用。
<%= f.fields_for(:questions, @survey.questions.sort_by(&:sort), {:id => "myId"}) do |question_form| %>
当我检查网页的来源时,我得到:
<div class="fields ui-sortable-handle">
...
<div>
我想得到类似这样的结果
<div class="fields ui-sortable-handle" id="myId">
...
</div>
答案 0 :(得分:1)
<%= f.fields_for :questions, @survey.questions.sort_by(&:sort), html: {id: "MyId", class: "MyClass"} do |question_form| %>
<!-- question_form block -->
<%end%>