adding class to select options

I have...

<%= select(:machine, :name, Machine.find(:all).map {|m| [,]}, {}, :class => "something" %>

This gives me....

<select class="something" id="machine_name" name="machine[name]"> <option value="12">AZ01</option> <option value="13">AZ02</option> <option value="14">AZ03</option>

What I am looking for is....

<select id="machine_name" name="machine[name]"> <option class ="something" value="12">AZ01</option> <option class ="something" value="13">AZ02</option> <option class ="something" value="14">AZ03</option>

How do you do this?



You can swap the order of the name and id fields in the array to get the right values and inner content in the option elements, but I don't think there's a convenient way to specify the CSS class of the option elements.

You can either build the elements yourself (maybe with content_tag) or add them using Javascript. It should be pretty easy to do with the Prototype library (which is included in Rails by default). Try using $$('select.something') to get the select element with the class "something", then addClassName("something") on each option child element.