for my rails3, devise, users model (name, email address, etc.). I want the forbidden domain names to be registered on the site.
The idea is that I have a list of blacklisted domains (badplace.com, hotmail.com) ... and when the new user record is saved, I will check the letter if it has a domain with a bad domain, I add a mistake.
So what is the right way to implement this in Rails ...
Here is what I played with:
In user model
protected
validates_each :email, :on => :create do |record, attr, value|
domain = email.split("@").last
record.errors.add attr, "That a BAD EMAIL." unless value && !value.contains(domain)
end
What do you think?
source
share