Get an array from a Rails form

后端 未结 5 1260
野趣味
野趣味 2021-01-12 13:10

I need to design a form for a account resource. In that form, i need to collect some set of ids as an array in the params hash in attribute called

5条回答
  •  青春惊慌失措
    2021-01-12 14:13

    You still need a fields_for in your view, just use :relationships as the record_name then provide an object.

    <%= form_for @account do |f| %>
        <%= f.text_field :name %>
    
        <% fields_for :relationships, @eligible_parents do |p| %>
            <%= p.check_box "relationships", nil, :value => p.object.id  %>
            <%= p.object.name %>
    <% end %> <%= f.submit "Submit" %> <% end %>

    Documentation here: ActionView::Helpers::FormHelper

提交回复
热议问题