I have defined a multiple select fields in my form:
index.html.haml
=form_for :mydata, {:url=>"/datas/render_datas", :method=>:post} do |form|
=select_tag('cars',options_from_collection_for_select(@cars, 'id', 'name'), {:multiple=>'multiple', :class=>'cars'})
= ...
=form.submit "Get"
when I submit my form, application calls the controller's render_datas
method:
class DatasController < ApplicationController
def render_datas
selected = params[:cars]
# I always get the last clicked car item
puts selected.to_s
end
end
From the rails console, I see the params holds the cars hash, but it always hold the last mouse clicked item, n开发者_如何学Cot the multiple selected array, why??? How to get rid of it?
I think your multiple
option should be :multiple => true
.
精彩评论