Rails 3 - 我可以将开始日期设置为 date_select 方法吗? [英] Rails 3 - Can I set start date to date_select method?

查看:42
本文介绍了Rails 3 - 我可以将开始日期设置为 date_select 方法吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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_yearend_year(即2015-2020),而不是 start_dateend_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.

一些可用的解决方法:

  1. 在服务器端进行验证并在提交的日期超出可接受范围时显示错误.
  2. 改用 JavaScript 客户端 - 例如 http://amsul.ca/pickadate.js/date/ - 允许限制开始和结束(也应该使用服务器端验证).
  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).

这篇关于Rails 3 - 我可以将开始日期设置为 date_select 方法吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆