Class: ReferenceValidator
- Inherits:
-
ActiveModel::EachValidator
- Object
- ActiveModel::EachValidator
- ReferenceValidator
- Defined in:
- lib/tram/validators/reference_validator.rb
Overview
Checks that a model instance can be found by id
Instance Method Summary collapse
Instance Method Details
#validate_each(record, attribute, value) ⇒ Object
7 8 9 10 11 12 13 |
# File 'lib/tram/validators/reference_validator.rb', line 7 def validate_each(record, attribute, value) model = .fetch(:model) { raise "You should define :model option" } key = .fetch(:find_by, :id) return if model.find_by(key => value) record.errors.add attribute, :not_found end |