【问题标题】:how to display years in date select descendingly?如何以降序显示日期选择的年份?
【发布时间】:2015-04-19 12:06:32
【问题描述】:

如何按降序显示年份?目前,我有这个:

<%= f.input :year_started, as: :date, label: "Date started", start_year: Date.today.year - 100, end_year: Date.today.year, discard_day: true, order: [:month, :year], include_blank: true, default: nil, :input_html => { :class => 'profile-date' } %>

下拉年份显示如下:

1900
1901
1902
....
2015

我想要相反,你是怎么做到的?:

2015
2014
2013
....
1900

谢谢。

【问题讨论】:

    标签: ruby-on-rails ruby-on-rails-4 simple-form


    【解决方案1】:

    我认为这就像交换 start_year 和 end_year 一样简单。

    试试:

    <%= f.input :year_started, as: :date, label: "Date started", start_year: Date.today.year, end_year: Date.today.year - 100, discard_day: true, order: [:month, :year], include_blank: true, default: nil, :input_html => { :class => 'profile-date' } %>
    

    它实际上在 API 文档中:http://apidock.com/rails/ActionView/Helpers/DateHelper/date_select#190-Get-year-to-show-in-descending-order-Today-to-192-for-example-

    【讨论】:

    猜你喜欢
    • 2010-09-21
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-02-22
    • 1970-01-01
    • 1970-01-01
    • 2011-05-06
    相关资源
    最近更新 更多