【问题标题】:Change the Range of Year Values within Date Type to Accommodate Possible Birth Years Rails, Simple_Form, HTML更改日期类型中的年份值范围以适应可能的出生年份 Rails、Simple_Form、HTML
【发布时间】:2015-01-22 23:03:26
【问题描述】:
<%= simple_form_for(@model) do |f| %>
    <%= f.input birthday %>

    <div class="form-actions">
        <%= f.button :submit, "Submit" %>
    </div>
<% end %>

默认月份和日期可以正常工作,但年份的选择范围太小了。默认值仅从 2010 年到 2020 年。如何更改它以使其范围从 1930 年到当年?

【问题讨论】:

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


    【解决方案1】:
     <%= simple_form_for(@model) do |f| %>
         <%= f.input :birthday, start_year: Date.today.year - 110, end_year: Date.today.year %>
    
         <div class="form-actions">
             <%= f.button :submit, "Submit" %>
         </div>
     <% end %>
    

    这给出了从当前年份到 110 年前的可能年份选择。

    在这里找到:http://apidock.com/rails/ActionView/Helpers/DateHelper/date_select

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-06-07
      • 1970-01-01
      相关资源
      最近更新 更多