views:

15

answers:

2

Hello!

I cannot figure out how to add a class to this select box in Rails 3.

<%= select(:item, :item_type, [['Phone', 1], ['Email', 2], ['Website', 3], ['Address', 4], ['Occupation', 5]]) %>

Is there anyone that knows how to do it?

Please help!

+1  A: 

Here's the official documentation for the select helper

<%= select(:item, :item_type, [['Phone', 1], ['Email', 2], ['Website', 3], ['Address', 4], ['Occupation', 5]], {}, :class => "myclass") %>
Simone Carletti
A: 

The parameters for select are the object, attribute, select list, a hash of method options, and a hash of html options, which have to be separate. If you want a 'toast' class, this works:

<%= select(:item, :item_type, [['Phone', 1], ['Email', 2], ['Website', 3], ['Address', 4], ['Occupation', 5]], {}, {:class => 'toast'}) %>

Note the empty hash - this needs to be here so that the method knows the following hash is for html options, which it passes directly onto the tag.

Jaime Bellmyer