<div class="form-group">
<%= f.label :date_of_birth %>
<p><%= f.date_select :date_of_birth, start_year: Date.today.year - 111, end_year: Date.today.year, class: 'form-control' %></p>
</div>
date_select
- t.datetime :date_of_birth
validate :model_condition
def model_condition
if self.date_of_birth < (Date.today.year - 111.year)
errors.add(:date_of_birth, "some error")
end
end
validate :model_condition
def model_condition
count = DateTime.now.year - 111
date_1905 = DateTime.new(count) # экземпляр даты за за прошедшие 111
# если дата не в назначеном диапазоне, выбивает ошибку и валидация не проходит
unless self.date_of_birth.between?(date_1905, DateTime.now)
errors.add(:date_of_birth, "some error")
end
end