Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

add class to collection_select

I've looked at How do I set the HTML options for collection_select in Rails? and I'm sure I'm missing something obvious, but I can't get this to work.

My select currently looks like:

  <%= f.collection_select :broadcast_id, broadcasts, :id, :to_s,
    :include_blank => 'Broadcast on...' %>

and I've tried including :class => 'prevent_collapse', which does nothing, as well as {:class => 'prevent_collapse'}, which gives me an error.

If anyone can point out how to do this, I'll be super grateful!

like image 878
tiswas Avatar asked Feb 09 '11 12:02

tiswas


2 Answers

collection_select(object, method, collection, value_method, text_method, options = {}, html_options = {})
=>
f.collection_select :broadcast_id, broadcasts, :id, :to_s,
{:include_blank => 'Broadcast on...'}, {:class => 'prevent_collapse'}

And what error do you have?

And does broadcast item has got :to_s method? It will return class name, as I think.

like image 172
fl00r Avatar answered Sep 20 '22 14:09

fl00r


Is that field :include_blank => {}, compulsory ? I tried with :include_blank => false and it worked. I wonder if we can avoid it ?

like image 39
Shyamkkhadka Avatar answered Sep 21 '22 14:09

Shyamkkhadka