How to add class to f.collection_select in Rails?

I have a form with this in the code

<%= f.collection_select :industry, Industry.all, :name, :name do %>
<% end %>

and I want to add a css class to it, what would be the best way of doing this? All my searched on Google haven’t resulted in anything useful.

I have tried

<%= f.collection_select :industry, Industry.all, :name, :class => "uk-select", :name do %>
<% end %>

and this didn’t work.

1 Like

Ok I found a solution, seeing that I didn’t need the block syntax I changed the code to

<%= f.collection_select :industry, Industry.all, :name, :name, {}, { class: "uk-select" } %>

which fixed everything.

2 Likes