Created
March 24, 2009 12:52
-
-
Save s-andringa/84067 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Person < ActiveRecord::Base | |
# If I18n.t is evaluated when the model is loaded, which in production happens only once | |
# the translation will always use the locale which was set at that moment. | |
# | |
# (Instead just use the activerecord.errors.person.attributes.email.invalid key in | |
# the translation files) | |
# | |
# This does NOT work properly: | |
validates_format_of :email, :with => REGEXP, :message => I18n.t(:email_invalid) | |
# Methods are evaluated on run time, so I18n.t works fine here: | |
def validate | |
errors.add(:email, I18n.t(:email_invalid)) unless email =~ REGEXP | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment