简体   繁体   中英

How to make hash/array of params out of several selects?

I have two select dropdowns and when a user selects an option from each of them It has to group them in the following manner:

job =>
  {
    "types" => [1,2,3]
  }

or at least like this:

job => {
  "types" => { "first" => "1", "second" => "2" }
}

Is this possible to do in Rails?

For example, this example only sends the last select value:

<%= simple_form_for @job, url: jobs_path do |f| %>

  <% 2.times do %>
    <%= f.input :types, as: :select, collection: @types %>
  <% end %>

<% end %>

改用多重select怎么样?

<%=f.select(:types, @types, multiple: true) %> 

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM