Rails 3 - 我可以将开始日期设置为 date_select 方法吗? [英] Rails 3 - Can I set start date to date_select method?
问题描述
date_select 方法只能设置:start_year,但我想设置开始日期(例如 3 个月前的日期)(但没有这样的选项).
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).
那么,我可以将开始日期设置为 date_select 方法吗?或者,要制作这样的选择框,我应该使用 select_tag 和 options_for_select 吗?或者,有什么解决办法吗?
so, can i set start date to date_select method? or, to make such the select box, should i use select_tag and options_for_select? or, are there any solutions?
谢谢,
推荐答案
date_select
助手只支持设置 start_year
和 end_year
(即2015-2020),而不是 start_date
和 end_date
(即 2015 年 6 月 1 日至 2020 年 7 月 1 日).date_select
助手的设计非常简单.如果仔细观察,您甚至会发现每个月都有 31 天.
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.
一些可用的解决方法:
- 在服务器端进行验证并在提交的日期超出可接受范围时显示错误.
- 改用 JavaScript 客户端 - 例如 http://amsul.ca/pickadate.js/date/ - 允许限制开始和结束(也应该使用服务器端验证).
- Do validations on the server side and present errors if dates are submitted that are outside an acceptable range.
- 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).
这篇关于Rails 3 - 我可以将开始日期设置为 date_select 方法吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!