ineedahero ineedahero - 8 months ago 67
Ruby Question

Rails Form: for multiple options

For my user form, I have a hobbies drop-down menu and I want to be able to select more than one option (one user may have skiing, reading, and chess as hobbies).

Of course, doing this is very easy!

However, none of the available options seem to work for me...

Here's my code:

<%= :hobbies, [['Chess','chess'],
['Skiing', 'skiing'],
{:multiple => true} %>

However, when I look at my form, I don't think this is working. It makes the drop-down menu....but how do I select multiple entries? I try ctr + click but it doesn't do anything....what am I missing? It keeps just selecting one value only...


Take a look at the accepted answer to that question - the method signature is:

select(:type, [data], {options hash}, {second options hash})

And in the answer, it has multiple: true in the second options hash.

API dock for select_tag gives a hint about what the two different hashes are for - it looks like the first options hash is for "option_tags", and the second one is for "options"