0
votes

I have found a few similar articles on stack but none of these examples seem to do the trick.

I'm calling map on an object, to create options in an f.select field, and I'm also using Include_blank option, then trying the class and the class will not work.

I've tried the following:

<%= f.select(:city_race_id, @city_races.map {|n| [n.office, n.id]}, include_blank: true,  html: { class: "form-control" }) %>

and

<%= f.select(:city_race_id, @city_races.map {|n| [n.office, n.id]}, include_blank: true, :class => 'form-control' ) %>

both render form and doesn't break rails, but neither show styling.

1
Does this answer your question? Ruby on Rails form_for select field with class - Clara

1 Answers

1
votes

Try this way :

  <%= f.select(:city_race_id, @city_races.map {|n| [n.office, n.id]}, {include_blank: "Select something"}, { :class => 'form-control' }) %>

select helper takes two options hashes, one for select, and the second for html options. you can also add prompt option.