Rails 3 - Can I set start date to date_select method?

前端 未结 2 465
[愿得一人]
[愿得一人] 2020-12-17 03:15

date_select method can only set :start_year, but i\'d like to set start date (e.g. date 3 months ago) (but there are no such options).

so, can i set start date to da

相关标签:
2条回答
  • 2020-12-17 03:41

    It is possible... e.g.

    :start_year – Set the start year for the year select. Default is Time.now.year - 5

    see this resource.

    0 讨论(0)
  • 2020-12-17 03:58

    The date_select helper only supports setting a start_year and end_year (i.e. 2015-2020), not a start_date and end_date (i.e. June 1st, 2015 to July 1st, 2020). The date_select helper is design to be very simple. If you look closely, you will even notice every month has 31 days.

    A few workarounds are available:

    1. Do validations on the server side and present errors if dates are submitted that are outside an acceptable range.
    2. Switch to using a JavaScript client - such as http://amsul.ca/pickadate.js/date/ - that allows limiting the start and end (should still use server side validations as well).
    0 讨论(0)
提交回复
热议问题