pass array hidden field in nested model rails

后端 未结 2 827
-上瘾入骨i
-上瘾入骨i 2021-01-29 04:35

I have following code in my view:

    <% @m1.map(&:id).each do |id|%>

    <%= b.fields_for :modul1hours do |f| %>

    <%= f.hidden_field :mo         


        
2条回答
  •  闹比i
    闹比i (楼主)
    2021-01-29 05:02

    In this line:

    <%= f.hidden_field :modul1_id, id %>
    

    You are saying that you want the hidden field binded with modul1hour modul1_id method and options being id. Second parameter for FormBuilder hidden_field is expected to be a hash (which is then merged against default options). To do what you want do:

    <%= f.hidden_field :modul1_id, value: id %>
    

提交回复
热议问题