Class: ActiveModel::Validations::RolesValidator
- Inherits:
-
EachValidator
- Object
- EachValidator
- ActiveModel::Validations::RolesValidator
- Defined in:
- lib/active_model/validations/roles_validator.rb
Instance Method Summary collapse
-
#initialize(options) ⇒ RolesValidator
constructor
A new instance of RolesValidator.
- #validate_each(record, attribute, value) ⇒ Object
Constructor Details
#initialize(options) ⇒ RolesValidator
Returns a new instance of RolesValidator.
10 11 12 13 |
# File 'lib/active_model/validations/roles_validator.rb', line 10 def initialize() @roles = [:roles] super end |
Instance Method Details
#validate_each(record, attribute, value) ⇒ Object
14 15 16 17 18 |
# File 'lib/active_model/validations/roles_validator.rb', line 14 def validate_each(record, attribute, value) unless value.split("_").all? {|x| @roles.include?(x) } record.errors[attribute] << ([:message] || "contains an invalid role") end end |