Forum: Ruby on Rails Setting a CSS class on select helper

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
0a87fb6bf40485e5a22b9c64a464e83b?d=identicon&s=25 Dan Weaver (jgoggles)
on 2008-12-19 23:37
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
0a87fb6bf40485e5a22b9c64a464e83b?d=identicon&s=25 Dan Weaver (jgoggles)
on 2008-12-20 00:10
I got it to work using:

<select class="monthSelect" id="order_month" name="order[month]">
 <%= options_for_select(1..12, Time.now.month.to_i) %>
</select>

Just curious, though, is that the only way to add a css class to that
type of thing?
C64e63b70be7dfed8b0742540b8b27e5?d=identicon&s=25 Mark Reginald James (Guest)
on 2008-12-20 00:22
(Received via mailing list)
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
0a87fb6bf40485e5a22b9c64a464e83b?d=identicon&s=25 Dan Weaver (jgoggles)
on 2008-12-20 00:28
Oh yeah! That's much cleaner.  Thanks for the reply.
This topic is locked and can not be replied to.