ineedahero
ineedahero

Reputation: 527

Rails Form: f.select 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:

<%= f.select :hobbies, [['Chess','chess'],
                        ['Movies','movies'],
                        ['Videogames','videogames'],
                        ['Skiing', 'skiing'],
                        ['Reading','reading']],
                        {: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...

Upvotes: 1

Views: 2268

Answers (1)

alexanderbird
alexanderbird

Reputation: 4198

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"

Upvotes: 2

Related Questions