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

"undefined method `copy' for nil" on save #2742

Closed
ssugiyama opened this issue May 15, 2024 · 7 comments
Closed

"undefined method `copy' for nil" on save #2742

ssugiyama opened this issue May 15, 2024 · 7 comments
Labels

Comments

@ssugiyama
Copy link

Due to 4c65b39, the following pseudo code begins to raise an error

class  ImageUploader < CarrierWave::Uploader::Base
  storage :fog 
  cache_storage :fog # maybe :file is alright
end

class Foo < ApplicationRecord
  mount_uploader :image, ImageUploader
end

...
class FooController < ApplicationController
... 
  def confirm
    @foo = Foo.new(image: params[:image], image_cache: params[:image_cache])
  end

  def complete
    @foo = Foo.new(image: params[:image], image_cache: params[:image_cache])
    @foo.save
  end
...
end

when complete method is called from confirm form which has f.hidden_field :image_cache and f.hidden_field :image , foo.save raises the following error.

undefined method `copy' for nil
        "/usr/local/bundle/bundler/gems/carrierwave-287e9a1924cb/lib/carrierwave/storage/fog.rb:444:in `copy_to'",
        "/usr/local/bundle/bundler/gems/carrierwave-287e9a1924cb/lib/carrierwave/storage/fog.rb:330:in `store'",
        "/usr/local/bundle/bundler/gems/carrierwave-287e9a1924cb/lib/carrierwave/storage/fog.rb:86:in `store!'",
        "/usr/local/bundle/bundler/gems/carrierwave-287e9a1924cb/lib/carrierwave/uploader/store.rb:97:in `block in store!'",
        "/usr/local/bundle/bundler/gems/carrierwave-287e9a1924cb/lib/carrierwave/uploader/callbacks.rb:15:in `with_callbacks'"

Due to 4c65b39, params[:image] turns to be the same as params[:image_cache]. Maybe this the reason of the behavior.

When the error was raised, the cache store seemed to have been already deleted.

@mshibuya mshibuya added the bug label Sep 15, 2024
@mshibuya
Copy link
Member

@ssugiyama
Thank you for reporting. I agree that this is better to be improved, but I want to understand one thing.
The expected usage is to have either f.hidden_field :image_cache or f.hidden_field :image, not both. What led you to to do so? Was there any instruction or something?

@ssugiyama
Copy link
Author

@mshibuya sorry for delay in my response

I make the entire form invisible, showing the image to users outside the form.
That's why both image_cache and image are hidden fields.
Maybe there's no need to worry about that as it's not essential.​​​​​​​​​​​​​​​​

@mshibuya
Copy link
Member

mshibuya commented Oct 2, 2024

Ah I meant, having both of :image_cache and :image is unexpected use case.
If you have followed the old way you should have only :image_cache. And with new way I'd recommend only having :image (mainly due to #2401).

So the question is, what's the reason you ended up having :image_cache and :image together?

@ssugiyama
Copy link
Author

ssugiyama commented Oct 4, 2024

I see! I just followed the old way. I will fix it to follow the current way.

@ssugiyama
Copy link
Author

Sorry for misreading you comment.

This is a legacy code of our project. I have misunderstood this is the correct way.

@ssugiyama
Copy link
Author

Maybe, we referred to this description. Do you mean the description is obsolete? @mshibuya

@mshibuya
Copy link
Member

What's there is file_field, not hidden_field. If what you referred to was that one you should have misunderstood something.
Anyway closing this, as this seems to be a very exceptional case. Thank you for reporting.

@mshibuya mshibuya closed this as not planned Won't fix, can't repro, duplicate, stale Oct 11, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants