custom validation for 1 attr

by menes on December 29th, 2011
No notes
Syntax: Ruby
Show lines - Hide lines - Show in textbox - Download
  1. class EmailUniquenessValidator < ActiveModel::EachValidator
  2. def validate_each(record, attribute, value)
  3. user = User::Account.find_by_email(value)
  4.  
  5. if user != nil
  6. record.errors.add(:base, I18n.t('user.webview.sign_up_error_msg')) # base errors are not specific to any attribute so it's not appended
  7. return false
  8. end
  9.  
  10. end
  11. end
  12.  
  13.  
  14. class User::Account < User::User
  15. validates :email, :email_uniqueness => true
  16. end
  17.  
  18.  
  19.  

Leave a Reply

Note: XHTML is allowed. Your email address will never be published.

Subscribe to this comment feed via RSS