Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>I just ran into this issue and found the original issue filed here: <a href="https://github.com/jnicklas/carrierwave/issues/481" rel="noreferrer">https://github.com/jnicklas/carrierwave/issues/481</a> and the wiki page describing the fix here: <a href="https://github.com/jnicklas/carrierwave/wiki/How-To%3A-Silently-ignore-missing-files-on-destroy-or-overwrite" rel="noreferrer">https://github.com/jnicklas/carrierwave/wiki/How-To%3A-Silently-ignore-missing-files-on-destroy-or-overwrite</a></p> <p>However I wasn't happy with the solution, I didn't want to have to add those 2 methods into all of my models that use an uploader. I tend to write 1 base uploader and subclass that for any changes to specific needs. So I dug into those methods: remove_#{column_name}! and remove_previously_stored_#{column_name} and found theme here: <a href="https://github.com/jnicklas/carrierwave/blob/master/lib/carrierwave/mount.rb#L204" rel="noreferrer">https://github.com/jnicklas/carrierwave/blob/master/lib/carrierwave/mount.rb#L204</a> and <a href="https://github.com/jnicklas/carrierwave/blob/master/lib/carrierwave/mount.rb#L204" rel="noreferrer">https://github.com/jnicklas/carrierwave/blob/master/lib/carrierwave/mount.rb#L204</a></p> <p>Both of these methods just call remove! on the uploader. So the easiest way to fix the issue is to override the remove! method in the uploader. Then you only need to override one method and in 1 place. My overrride looks like the following:</p> <pre><code>class CloudfilesUploader &lt; CarrierWave::Uploader::Base # Override to silently ignore trying to remove missing previous file def remove! begin super rescue Fog::Storage::Rackspace::NotFound end end end </code></pre> <p>That should solve your problems when trying to re-upload an image and overwrite an image that doesn't exist or when you just try and delete an image that doesn't exist.</p> <p>~ Tom</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload