I got stuck for last half an hour at ‘getting the values of multiple selected items in a muliple selection box’ using Ruby/Rails. Got it after hard ‘googling’ and got the solution here.
When trying to get multiple selected values from a <SELECT> tag into @params, call your parameter something with [] on the end. That way rails knows it’s multiple.
So instead of
<select name="job[techs]" size="5" multiple="multiple">
Use:
<select name="job[techs][]" size="5" multiple="multiple">
Thanks google and Ruby/Rails community !
Filed under: Programming, Rails, Ruby, technical
Thanks for posting this. It fixed me up in 30 seconds!
You can also use the select_tag like so:
true%>
This assumes that you have “has_many :techs” in your Job class.
ack! The thing ate all my text since it contained brackets… dang…
select_tag “job[tech_ids][]“, options_from_collection_for_select(@all_techs, “id”, “name”), :multiple=>true
Thanks! This was just what I needed.