2010-11-06 43 views
1

我最近添加了一個出生日期字段到我的設計註冊頁面,並使用validates_timeliness來檢查它的日期是否正確。但是,如果日期空白,我會得到下面的錯誤,不知道如何解決它。添加日期到設計,現在得到錯誤

* 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 

控制器

#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 

在行動的形式,如果你需要看到它。 http://hangwith.me/account/register

回答

2

設計是完全國際化的,並希望您定義用戶輸入無效日期時應該收到的錯誤消息。

要解決這個問題,你需要在你的國際化配置來定義相關的字符串,像這樣:

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)!' 

另外,如果你想允許用戶無需輸入的日期進行(這不是很清楚從你的問題),你應該在你的validates_timeliness驗證上設置:allow_blank

+0

完美,正是我所需要的。謝謝! – Jason 2010-11-06 19:04:02