问题
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