cssruby-on-railstwitter-bootstrapcollection-select

Add class to collection_select on Ruby On Rails formulary


I'm using a form for create a record in RoR. I've dropdown menu and I don't know how to add a class for styling this element.

Code:

<%= f.collection_select :id, TipusProducte.order(:nom),:id ,:nom, include_blank: false, class: "btn btn-secondary dropdown-toggle" %>

But this class doesn't work, this style is from Bootstrap.

Thanks!


Solution

  • You're doing it right, but you need to separate the hashes:

    <%= f.collection_select :id, TipusProducte.order(:nom),:id ,:nom, { include_blank: false }, { class: "btn btn-secondary dropdown-toggle" } %>
    

    Otherwise, it gets interpreted as one hash. The function spec has two object hashes as arguments; the first is for collection options, the second for HTML options.