-
-
Notifications
You must be signed in to change notification settings - Fork 94
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add rails 7 version specific fix for AttachmentSizeValidator #73
Conversation
unless value.send(CHECKS[option], option_value) | ||
operator = Rails::VERSION::MAJOR >= 7 ? COMPARE_CHECKS[option] : CHECKS[option] | ||
|
||
unless value.send(operator, option_value) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Style/Next: Use next to skip iteration.
|
||
unless value.send(CHECKS[option], option_value) | ||
operator = Rails::VERSION::MAJOR >= 7 ? COMPARE_CHECKS[option] : CHECKS[option] | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Layout/TrailingWhitespace: Trailing whitespace detected.
@@ -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] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Metrics/LineLength: Line is too long. [91/80]
@ssinghi I was just about to look into this and have seen that there is already a fix in place. Would it be possible to create a 7.0.2 tag that contains this fix at all please? |
I'm using master and still getting an error using 7.0.3.1:
|
I see the problem. Some extensions require paperclip in the Gemfile. Is there a way to satisfy that dependency with kt-paperclip? |
Is this pushed onto the master branch yet? I'm having the same issue and I'm running 6.4.2. |
I put this in an initializer. module Paperclip
module Validators
class AttachmentSizeValidator
CHECKS = COMPARE_CHECKS
end
class AttachmentPresenceValidator < ActiveModel::EachValidator
def validate_each(record, attribute, value)
if record.send("#{attribute}_file_name").blank?
record.errors.add(attribute, :blank, **options)
end
end
def self.helper_method_name
:validates_attachment_presence
end
end
end
end |
You are the real MVP! Thank you. This fixed my issue with it. |
@atomical thank you |
I compared the
COMPARE_CHECKS
(Rails 7) andCHECKS
(Rails 6) - This can be replaced directly.