How to keep the same filename in carrierwave when updating a file (in rails)
<p>When an image is updated using carrierwave I have it setup to use the model id and original file name </p>

<pre><code>def filename
 "#{model.id}-#{original_filename}" if original_filename.present?
end
</code></pre>

<p>Its only like this because its the default way I found when I was setting up carrierwave. Recently I realised if you update an image the link to the image is broken because the filename is updated to use the newer files name. So if a page is linked to the old image it isn't updated with the newer image but instead becomes a broken image link.</p>

<p>I want it to keep the old file name when the image is being updated but cant find how to do this in the documentation and from googling around</p>

<p><strong>Edit</strong></p>

<p>I diddnt add a lot of the 'use case' because I diddnt think the problem was this complicated.</p>

<p>Basically on the site there are <code>items</code> that have <code>images</code> assigned to them. I did see the comment on not using only <code>model.id</code> and @struthersneil cleared up why that comment is there. Considering the <code>images</code> records for an items are created when the item is created they will never be new when the image is being added (because its just updating a record that already exists). Because of this I'd say my best bet is to use just <code>model.id</code> as the filename.</p>

<p>My other option is to keep the old image so the links aren't broken. The main problem for using this is that users create posts on the site and link to these images in the posts (the posts are regularly updated so I cant to a once off cache on the post and images in the post). The images become updated from new information on the items they are associated to. Once this happens the image linked in the post will show outdated information and they will have to manually update to the new image each time. So having the image link stay the same with the image being updated is the best option in this case particular case</p>