send data to an array from 2 collection select boxes
I have controller with an action step2 which collects all devices by selected category. 开发者_运维问答My step2.html.erb looks like:
<% form_for compare_comparision_path, :url => {:action => 'comparision'} do |f| %>
<%= f.collection_select(:device, @devices, :id, :name, options ={:prompt => "Select"}, :class=>'device') %>
</br>
<%= f.collection_select(:device, @devices, :id, :name, options ={:prompt => "Select"}, :class=>'device') %>
<%= f.submit 'ok' %>
<% end %>
I want for it to allow the user to select two devices and send it to some array or variable in comparison action.
You can do so:
<% form_for compare_comparision_path, :url => {:action => 'comparision'} do |f| %>
<%= f.collection_select('device[]', @devices, :id, :name, options ={:prompt => "Select"}, :class=>'device') %>
</br>
<%= f.collection_select('device[]', @devices, :id, :name, options ={:prompt => "Select"}, :class=>'device') %>
<%= f.submit 'ok' %>
<% end %>
and in controller you`ll have an array in params[:device] containing to selected values.
Or you can replace 'device[]' in my example with unique name for each selectbox (for example 'devise1' and 'device2'.
Then you can get selected values in controller by accessing params[:device1] and params[:device2]
精彩评论