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

"NoMethodError: undefined method []' for #[ModelWithAttachment] #23

Open
katyp opened this issue Jan 5, 2021 · 0 comments
Open

"NoMethodError: undefined method []' for #[ModelWithAttachment] #23

katyp opened this issue Jan 5, 2021 · 0 comments

Comments

@katyp
Copy link

katyp commented Jan 5, 2021

Hi!

I'm getting the following error:

"NoMethodError: undefined method []' for #ModelWithAttachment:0x000055d59c8c0cb8"

With stack trace:

paperclip-azure-1.0.4/lib/paperclip/storage/azure.rb:146:in `obtain_azure_instance_for'
paperclip-azure-1.0.4/lib/paperclip/storage/azure.rb:130:in `azure_interface'
paperclip-azure-1.0.4/lib/paperclip/storage/azure.rb:163:in `azure_container'
paperclip-azure-1.0.4/lib/paperclip/storage/azure.rb:203:in `block in flush_writes'
paperclip-azure-1.0.4/lib/paperclip/storage/azure.rb:194:in `each'
paperclip-azure-1.0.4/lib/paperclip/storage/azure.rb:194:in `flush_writes'
paperclip-5.2.1/lib/paperclip/attachment.rb:247:in `save'

(I have replaced my model name with "ModelWithAttachment")

I believe it is due to what appears to be a typo here:

      def obtain_azure_instance_for(options)
        instances = (Thread.current[:paperclip_azure_instances] ||= {})
        return instances[options] if instance[options]

The code checks for instance[options] in order to return instances[options]. Well, instance should be probably be plural there. The funny thing is that instance is also defined on the attachment, from the paperclip gem: it's the instance on which the attachment lives, so instead of seeing an error like "No such method: instance", this shows up as an error that the instance doesn't support the [] method.

I'm surprised that this code is working for anyone given that it impacts saving models with attachments. This leads me to question the conclusion I've drawn, but at the same time the code looks pretty clearly like it intends to use the plural there.

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