我使用导轨date_select
和time_select
以及以下选项。
但对于date_select
start_year
和end_year
以及order
选项不起作用。并且time_select
ampm:true
选项无效。
<%= label_tag :date,"Date" %>
<%= date_select :date, { start_year: Date.today.year - 1, :end_year => Date.today.year, order: [:day, :month, :year] } %>
<%= label_tag :check_in,"Check In Time" %>
<%= time_select :check_in, {ampm: true} , {} %>
<%= label_tag :check_out,"Check Out Time" %>
<%= time_select :check_out, {ampm: true}, {} %>
以及如何应用类属性。我喜欢这样,但造型不起作用。
<%= time_select :check_out, {ampm: true} ,{:class => 'form-control' } %>
答案 0 :(得分:2)
在Rails上API docs date_select
定义为
date_select(object_name,method,options = {},html_options = {})
当你应该是第三个参数时,你将options
作为第二个参数。
解决方案1:
<%= date_select :date, nil, { start_year: Date.today.year - 1, :end_year => Date.today.year, order: [:day, :month, :year] } %>
存在同样的问题
time_select(object_name,method,options = {},html_options = {})
解决方案2:
<%= time_select :check_out, nil, {ampm: true} ,{:class => 'form-control' } %>
答案 1 :(得分:1)
参数顺序错误。它应该是:
<%= label_tag :date,"Date" %>
<%= date_select :date, {}, { start_year: Date.today.year - 1, :end_year => Date.today.year, order: [:day, :month, :year] } %>
<%= label_tag :check_in,"Check In Time" %>
<%= time_select :check_in, {}, {ampm: true} %>
<%= label_tag :check_out,"Check Out Time" %>
<%= time_select :check_out, {}, {ampm: true} %>
另请参阅:http://api.rubyonrails.org/classes/ActionView/Helpers/DateHelper.html#method-i-date_select