我可以为fields_for的div设置一个id吗?

时间:2019-03-08 05:28:33

标签: html ruby-on-rails

我想为来自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>

1 个答案:

答案 0 :(得分:1)

fields_for

   <%= f.fields_for :questions, @survey.questions.sort_by(&:sort), html: {id: "MyId", class: "MyClass"} do |question_form| %>
      <!-- question_form block -->
    <%end%>