Added date to Devise and now getting errors
I recently added a date of birth field to my devise registration page and use validates_timeliness to check that the date it right. However, 开发者_StackOverflowif the date is left blank I get the below error and not sure how to fix it.
* Date of birth translation missing: en, activerecord, errors, models, user, attributes, date_of_birth, invalid_date
* Date of birth translation missing: en, activerecord, errors, models, user, attributes, date_of_birth, invalid_date
controller
#validates_timeliness gem is used for validates_date
validates_date :date_of_birth, :before => lambda { 18.years.ago }, :before_message => "must be at least 18 years old"
validates_date :date_of_birth, :after => lambda { 106.years.ago }, :before_message => "Seriously, dude. You ain't that old."
validates_acceptance_of :terms_of_service, :accept => true
validates_presence_of :gender_id
form in action if you need to see it. http://hangwith.me/account/register
Devise is completely internationalised and wants you to define what error message the user should receive if they enter an invalid date.
To fix this, you need to define the relevant strings in your i18n config like so:
en:
activerecord:
errors:
models:
user:
attributes:
date_of_birth:
invalid_date: 'You must be over 18 to use HangWith.me (and not too old either)!'
Also, if you would like to allow the user to proceed without entering a date (it's not quite clear from your question), you should set :allow_blank
on your validates_timeliness validation.
精彩评论