How do I use the Bootstrap form select css with a Rails model? How do I use the Bootstrap form select css with a Rails model? ruby ruby

How do I use the Bootstrap form select css with a Rails model?


First of all, for bootstrap's form-control class to work, you must add it to select tag itself

Per apidoc of rails form select

select(object, method, choices = nil, options = {}, html_options = {}, &block)

you can add html class as

<%= f.select(:ampm, options_for_select([['AM', 1], ['PM', 2]]), {}, {class: "form-control"}) %>

or simply

<%= f.select :ampm, [['AM', 1], ['PM', 2]], {}, {class: "form-control"}) %>


This works for me:

<%= f.select :secretquestion, options_for_select([  ["Select One", ""],   "Your nick name",   "your schoool name",   "your love name",   "your comapnay name",   "your favourite website"]),   {}, { class: "form form-group form-control" } %>