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

NameError: uninitialized constant Paperclip::Storage::Fog::Excon (Zeitwerk?) #100

Open
viktorianer opened this issue Nov 4, 2022 · 1 comment

Comments

@viktorianer
Copy link

Describe the bug
First, thank you for keeping updating this cool gem.

I think we have found a bug, probably related to Rails Zeitwerk mode, where we get NameError, when we use Paperclip to store or update PDF files.

When we try to assign a document to a record with Paperclip attachment: bill.update document: pdf_document
We will see this error:

NameError: uninitialized constant Paperclip::Storage::Fog::Excon
from .bundle/ruby/3.0.0/gems/kt-paperclip-7.1.1/lib/paperclip/storage/fog.rb:120:in `rescue in block in flush_writes'
Caused by NameError: uninitialized constant Fog
from .bundle/ruby/3.0.0/gems/kt-paperclip-7.1.1/lib/paperclip/storage/fog.rb:232:in `connection'

See https://github.com/kreeti/kt-paperclip/blob/master/lib/paperclip/storage/fog.rb#L120

I also tried to activate config.autoloader = :classic mode, bud got the same error.

After adding gem "fog-aws", "~> 3.15.0", I got a new error:

TypeError: wrong argument type Class (expected Module)
from /home/nonroot/.bundle/ruby/3.0.0/gems/kt-paperclip-7.1.1/lib/paperclip/attachment.rb:425:in `extend'

See https://github.com/kreeti/kt-paperclip/blob/master/lib/paperclip/attachment.rb#L425

So, I have no idea, how to solve it.

Additional context
We are in process to upgrade old application from Rails 5 to 6.1 and Ruby 2.5.x to 3.0.4.
We followed Rails Guides, in order to upgrade, e.g.:

https://edgeguides.rubyonrails.org/upgrading_ruby_on_rails.html#autoloading
https://edgeguides.rubyonrails.org/classic_to_zeitwerk_howto.html
https://edgeguides.rubyonrails.org/autoloading_and_reloading_constants.html

@viktorianer
Copy link
Author

I just tried to update to the latest version of kt-paperclip and aws-sdk-s3. On our review Heroku instance, it works now! But I get this error in local environment (macOS 12.5.1 or Docker Alpine).

Because I do not have credentials for S3 bucket, I tried with defaults from README, where storage: :fog is set to fog. And maybe this is the issue here?!

Why I should use fog for local development?

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

1 participant