简体   繁体   中英

date_select and time_select are not taking the start_year and end_year and order parameters in rails?

im using the rails date_select and time_select with the following options. but for date_select start_year and end_year and order options are not working. and for time_select ampm:true option is not working.

    <%= 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}, {}   %>

and how to apply class attribute. iam giving like this but styling is not working.

    <%= time_select :check_out, {ampm: true} ,{:class => 'form-control' }  %>

on Rails API docs the date_select is defined as

date_select(object_name, method, options = {}, html_options = {})

you are placing options as the second parameter when it should be the third one.

solution 1:

<%= date_select :date, nil, { start_year: Date.today.year - 1, :end_year => Date.today.year, order: [:day, :month, :year] }  %>

You have the same problem for the time_select :

time_select(object_name, method, options = {}, html_options = {})

solution 2:

 <%= time_select :check_out, nil, {ampm: true} ,{:class => 'form-control' }  %>

The parameters are in the wrong order. It should be:

<%= 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}   %>

See also: http://api.rubyonrails.org/classes/ActionView/Helpers/DateHelper.html#method-i-date_select

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM