Move password validation into PasswordValidator

This commit is contained in:
Neil Lalonde
2013-12-19 15:12:03 -05:00
parent 4f7d440fa4
commit 33c6997ded
3 changed files with 70 additions and 6 deletions

View File

@ -0,0 +1,12 @@
class PasswordValidator < ActiveModel::EachValidator
def validate_each(record, attribute, value)
return unless record.password_required?
if value.nil?
record.errors.add(attribute, :blank)
elsif value.length < 6
record.errors.add(attribute, :too_short, count: 6)
end
end
end