Rails-date_select不允许选择过去的日期 [英] Rails - date_select not allow to choose past date
本文介绍了Rails-date_select不允许选择过去的日期的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在使用以下代码
<%= f.date_select 'event_date', selected: Date.today, :start_year => Date.today.year, :end_year => Date.today.year + 1 %>
我想禁止人们从现在起至少5天之内选择数据.最长不超过1年如何设置日期和月份?
I want to ban people from choosing data at a min of 5 days from now. and max of 1 year max. How can i set the date and month?
还是我应该在模型验证中这样做?
Or should i do this in model validation?
推荐答案
来自此答案:您应该能够给出 min
和 max
日期:
You should be able to give the min
and max
dates:
f.date_select 'event_date', selected: Date.today, min: 5.days.ago, max: 1.year.from_now
这篇关于Rails-date_select不允许选择过去的日期的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文