Rails - date_select not allow to choose past date

╄→尐↘猪︶ㄣ 提交于 2020-12-12 11:09:46

问题


I am using the following code

<%= f.date_select 'event_date', selected: Date.today, :start_year => Date.today.year, :end_year => Date.today.year + 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?


回答1:


From this answer: Rails 4 date_field, min and max year?

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


来源:https://stackoverflow.com/questions/33260326/rails-date-select-not-allow-to-choose-past-date

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!