I use Paperclip to manage uploaded images for a specific model in Rails 3. This belongs_to model belongs_to different model. I want my image path to reflect this relationship, so for this I created custom interpolation.
The problem is that I also want to be able to edit the name of belongs_to objects, and I would like Paperclip to rename the files accordingly.
Here is a simple example:
class Make < ActiveRecord:Base attr_accessible :name has_many :models end class Model < ActiveRecord:Base attr_accessible :img, :make, :name belongs_to :make has_attached_file :img, :style => { :thumb => "100x100" }, :path => "/cars/:make_name/:name/:style/:hash.png", :hash_secret => "blabla" Paperclip.interpolates :make_name do |attachment, style| attachment.instance.make.name end Paperclip.interpolates :name do |attachment, style| attachment.instance.name end end
So let's say I create make Chevrolet and Model Camaro , my image path will be /cars/chevrolet/camaro/thumb/my_hash.png
If I decide to change the Chevrolet record name to Chevy , Rails will try to find the image in /cars/chevy/camaro/thumb/my_hash.png , but since the image was not renamed, it was not found.
How to get Paperclip to update all image paths when renaming a record?
Thanks!
source share