Skip to content

Commit

Permalink
Add rails 7 version specific fix for AttachmentSizeValidator (kreeti#73)
Browse files Browse the repository at this point in the history
  • Loading branch information
yorzi authored Dec 14, 2021
1 parent 0b7bb0b commit c9e6f9d
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions lib/paperclip/validators/attachment_size_validator.rb
Original file line number Diff line number Diff line change
@@ -35,8 +35,9 @@ def validate_each(record, attr_name, value)
options.slice(*AVAILABLE_CHECKS).each do |option, option_value|
option_value = option_value.call(record) if option_value.is_a?(Proc)
option_value = extract_option_value(option, option_value)

unless value.send(CHECKS[option], option_value)
operator = Rails::VERSION::MAJOR >= 7 ? COMPARE_CHECKS[option] : CHECKS[option]

unless value.send(operator, option_value)
error_message_key = options[:in] ? :in_between : option
error_attrs.each do |error_attr_name|
record.errors.add(error_attr_name, error_message_key, **filtered_options(value).merge(

0 comments on commit c9e6f9d

Please sign in to comment.