Skip to content

Commit

Permalink
Merge pull request #369 from yivo/master
Browse files Browse the repository at this point in the history
Fallback to ActiveModel translations in EmailValidator
  • Loading branch information
booleanbetrayal committed Nov 9, 2015
2 parents 3ccd330 + 31a1618 commit 1feace6
Showing 1 changed file with 16 additions and 2 deletions.
18 changes: 16 additions & 2 deletions app/validators/email_validator.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,21 @@
class EmailValidator < ActiveModel::EachValidator
def validate_each(record, attribute, value)
unless value =~ /\A([^@\s]+)@((?:[-a-z0-9]+\.)+[a-z]{2,})\z/i
record.errors[attribute] << (options[:message] || I18n.t("errors.not_email"))
record.errors[attribute] << email_invalid_message
end
end
end

private

def email_invalid_message
# Try strictly set message:
message = options[:message]

if message.nil?
# Try DeviceTokenAuth translations or fallback to ActiveModel translations
message = I18n.t(:'errors.not_email', default: :'errors.messages.invalid')
end

message
end
end

0 comments on commit 1feace6

Please sign in to comment.