Skip to content
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

wrong number of arguments (given 3, expected 1..2) with validations on Rails 6.1 #46

Closed
rmehner opened this issue Jan 28, 2021 · 9 comments

Comments

@rmehner
Copy link

rmehner commented Jan 28, 2021

Describe the bug

When using kt-paperclip on Rails 6.1, when using validations that will trigger errors, Rails will throw a wrong number of arguments (given 3, expected 1..2) error.

See rails/rails#41270 for details on that.

To Reproduce

class User < ApplicationRecord
  has_attached_file :avatar
  validates_attachment_presence :avatar, if: :confirmed?
end

This will trigger the error, if avatar is missing

Expected behavior

Should not trigger the error.

Additional context

Changing https://github.com/kreeti/kt-paperclip/blob/master/lib/paperclip/validators/attachment_presence_validator.rb#L7 to:

record.errors.add(attribute, :blank, **options) if record.send("#{attribute}_file_name").blank?

Fixes it for the presence validator. Not sure how compatible that would be to older versions though.

@ssinghi
Copy link

ssinghi commented Jan 29, 2021

@rmehner If you can please create a PR for this, we can then take it forward. thanks!

@rmehner
Copy link
Author

rmehner commented Jan 29, 2021

@ssinghi was planning to, but bundle install is stuck on Resolving dependencies for over 1h now on this project, so I can't run the tests. I might just do the changes and let the CI deal with it :)

@v-kumar
Copy link

v-kumar commented Jan 29, 2021

@rmehner it is because of all the ruby versions and the needed gems. Takes a long time without proper RVM setup for all required ruby versions. I would recommend creating a PR and let Travis deal with it. Or, my PR just got merged and I can do this for you.

@rmehner
Copy link
Author

rmehner commented Jan 29, 2021

It's stuck at the bundle install step, I've stopped it after 2 hours. I'll use CI for that then and will provide a PR soon-ish.

@brendon
Copy link

brendon commented May 17, 2021

Hi @ssinghi, would you be able to release a gem with this fix in it? :)

@ssinghi
Copy link

ssinghi commented May 28, 2021

New gem version v7.0.0 released as well .

@ssinghi ssinghi closed this as completed May 28, 2021
@brendon
Copy link

brendon commented May 28, 2021

Thanks @ssinghi. Much appreciated :D

@rmehner
Copy link
Author

rmehner commented May 31, 2021

Can confirm this works as expected. Thanks for your work @ssinghi, didn't came around to do it for myself.

@nijeesh-rently
Copy link

nijeesh-rently commented Nov 21, 2024

  module Paperclip::Validators::MonkeyPatches
    def mark_invalid(record, attribute, types)
      record.errors.add attribute, :invalid, **options.merge(:types => types.join(', '))
    end
  end
  
  Paperclip::Validators::AttachmentContentTypeValidator.prepend(Paperclip::Validators::MonkeyPatches)
  Paperclip::Validators::AttachmentFileNameValidator.prepend(Paperclip::Validators::MonkeyPatches)

if you can't update the gem. This mokeypatch does fix that problem for me.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants