I have three select fields in my view:
<%= select("policyholderdetail", "dob_day", days_options, {:prompt => "#{t :day}"}) %>
<%= select("policyholderdetail", "dob_month", months_options, {:prompt => "#{t :month}"}) %>
<%= select("policyholderdetail", "dob_year", dob_years_options, {:prompt => "#{t :year}"}) %>
Where the values for :dob_day range from 01-31, :dob_month from 01-12 and dob_year from 1912-2012 (last 100 years)
I would like to validate that someone’s date of birth from this is at least 17 years ago, i.e. the person is at least 17 years old. How can I do this in my rails model?
First you want to make sure that you’re saving only one DateTime to represent all three fields.
Then you just work against that date :
Tip..
Outside of the specific answer, I would recommend that your DateOfBirth field is just one field and that those three selects represent one column in your table.