Class: Intermodal::Validators::AccountValidator
- Inherits:
-
ActiveModel::EachValidator
- Object
- ActiveModel::EachValidator
- Intermodal::Validators::AccountValidator
- Defined in:
- lib/intermodal/validators/account_validator.rb
Overview
Validates the associated resource is owned by the same account Examples:
validates parent_id, account: true validates parent_id, account: { through: association }
Instance Method Summary collapse
Instance Method Details
#message ⇒ Object
19 20 21 |
# File 'lib/intermodal/validators/account_validator.rb', line 19 def [:message] || 'must belong to the same account' end |
#validate_each(record, attribute, value) ⇒ Object
12 13 14 15 16 17 |
# File 'lib/intermodal/validators/account_validator.rb', line 12 def validate_each(record, attribute, value) return if value.nil? association_name = [:through] || attribute.to_s.gsub(/_id/, '') return if record.send(association_name).account_id == record.account_id record.errors[attribute] << end |