# Setting a CSS class on select helper

**URL:** <https://www.ruby-forum.com/t/setting-a-css-class-on-select-helper/156066>\
**Category:** Rails\
**Created:** [December 19, 2008, 11:37pm UTC](https://www.ruby-forum.com/t/setting-a-css-class-on-select-helper/156066 "2008-12-19T23:37:04Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![dan](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/eada6e/32.png) [@dan](https://www.ruby-forum.com/u/dan)\
**Post date:** [December 19, 2008, 11:37pm UTC](https://www.ruby-forum.com/t/setting-a-css-class-on-select-helper/156066/1 "2008-12-19T23:37:04Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![dan](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/eada6e/32.png) [@dan](https://www.ruby-forum.com/u/dan)\
**Post date:** [December 20, 2008, 12:10am UTC](https://www.ruby-forum.com/t/setting-a-css-class-on-select-helper/156066/2 "2008-12-20T00:10:47Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![dan](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/eada6e/32.png) [@dan](https://www.ruby-forum.com/u/dan)\
**Post date:** [December 20, 2008, 12:22am UTC](https://www.ruby-forum.com/t/setting-a-css-class-on-select-helper/156066/3 "2008-12-20T00:22:34Z")

</div>

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](http://railswheels.com)

---

<div class="post-metadata">

**Author:** ![dan](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/eada6e/32.png) [@dan](https://www.ruby-forum.com/u/dan)\
**Post date:** [December 20, 2008, 12:28am UTC](https://www.ruby-forum.com/t/setting-a-css-class-on-select-helper/156066/4 "2008-12-20T00:28:55Z")

</div>

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