Setting a CSS class on select helper

Hi,

I’m trying to put a css class on a dropdown box built using a select
helper (to make it wider) but I can’t get it to take. I thought for
sure, and from what I’ve seen elsewhere, this code should work:

<%= f.select :month, 1…12, :selected => Time.now.month.to_i, :class =>
‘monthSelect’ %>

Suggestions?

Thanks

I got it to work using:

<%= options_for_select(1..12, Time.now.month.to_i) %>

Just curious, though, is that the only way to add a css class to that
type of thing?

Dan Weaver wrote:

Hi,

I’m trying to put a css class on a dropdown box built using a select
helper (to make it wider) but I can’t get it to take. I thought for
sure, and from what I’ve seen elsewhere, this code should work:

<%= f.select :month, 1…12, :selected => Time.now.month.to_i, :class =>
‘monthSelect’ %>

You have to make sure Ruby sees two separate hash arguments:

<%= f.select :month, 1…12, {:selected => Time.now.month.to_i},
:class => ‘monthSelect’ %>


Rails Wheels - Find Plugins, List & Sell Plugins -
http://railswheels.com

Oh yeah! That’s much cleaner. Thanks for the reply.