Module: ActiveStorageValidations::ASVErrorable
- Extended by:
- ActiveSupport::Concern
- Included in:
- AspectRatioValidator, AttachedValidator, BaseComparisonValidator, ContentTypeValidator, DimensionValidator, LimitValidator, ProcessableFileValidator
- Defined in:
- lib/active_storage_validations/shared/asv_errorable.rb
Instance Method Summary collapse
- #add_error(record, attribute, error_type, **errors_options) ⇒ Object
- #initialize_error_options(options, file = nil) ⇒ Object
Instance Method Details
#add_error(record, attribute, error_type, **errors_options) ⇒ Object
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/active_storage_validations/shared/asv_errorable.rb', line 20 def add_error(record, attribute, error_type, **) return if record.errors.added?(attribute, error_type) error = record.errors.add(attribute, error_type, **) # Rails 8.0.2 introduced a new way to mark errors as nested # https://github.com/igorkasyanchuk/active_storage_validations/issues/377 if Rails.gem_version >= Gem::Version.new("8.0.2") # Mark errors as nested when they occur in a parent/child context set_nested_error(record, error) if updating_through_parent?(record) end # You can read https://api.rubyonrails.org/classes/ActiveModel/Errors.html#method-i-add # to better understand how Rails model errors work error end |
#initialize_error_options(options, file = nil) ⇒ Object
7 8 9 10 11 12 13 14 15 16 17 18 |
# File 'lib/active_storage_validations/shared/asv_errorable.rb', line 7 def (, file = nil) = %i[with in] = .except(*) = { validator_type: self.class.to_sym, custom_message: ([:message] if [:message].present?), filename: (get_filename(file) unless self.class.to_sym == :total_size) }.compact .merge() end |