Module: ActiveStorageValidations::ErrorHandler
- Included in:
- AspectRatioValidator, AttachedValidator, ContentTypeValidator, DimensionValidator, LimitValidator, ProcessableImageValidator, SizeValidator
- Defined in:
- lib/active_storage_validations/error_handler.rb
Instance Method Summary collapse
- #add_error(record, attribute, error_type, **errors_options) ⇒ Object
- #initialize_error_options(options) ⇒ Object
Instance Method Details
#add_error(record, attribute, error_type, **errors_options) ⇒ Object
11 12 13 14 15 16 17 18 |
# File 'lib/active_storage_validations/error_handler.rb', line 11 def add_error(record, attribute, error_type, **) type = [:custom_message].presence || error_type return if record.errors.added?(attribute, type) # You can read https://api.rubyonrails.org/classes/ActiveModel/Errors.html#method-i-add # to better understand how Rails model errors work record.errors.add(attribute, type, **) end |
#initialize_error_options(options) ⇒ Object
4 5 6 7 8 9 |
# File 'lib/active_storage_validations/error_handler.rb', line 4 def () { validator_type: self.class.to_sym, custom_message: ([:message] if [:message].present?) }.compact end |