问题
Bootstrap has the class 'form-control' to add to select boxes to give them styling. I was able to do it successfully so for the following field:
<%= f.collection_select :team_a_id, @teams, :id, :name, {prompt: "Select first team"}, {class: "form-control"} %>
However I have the following form field for time_select. I need to apply an html class(preferably "form-control") to the following form field and have not been successful in doing so with the same approach above.
<%= f.time_select :match_time, prompt: {hour: 'Choose hour', minute: 'Choose minute'}, minute_step: 15 %>
How would I approach this problem?
回答1:
The html_options is the third parameter, as described in the docs:
time_select(method, options = {}, html_options = {})
so something like this should work:
<%= f.time_select :method, { prompt: {hour: 'Choose hour', minute: 'Choose minute'}, minute_step: 15 }, { class: 'form-control' } %>
回答2:
From DOCs
time_select(object_name, method, options = {}, html_options = {})
Probably you are looking smth like this:
<%= f.time_select :match_time, '', {prompt: {hour: 'Choose hour', minute: 'Choose minute'}, minute_step: 15}, class: "form-control" %>
来源:https://stackoverflow.com/questions/37353083/adding-a-bootstrap-class-to-rails-form-time-select-field