Update paths of already-created Paperclip attachments

Posted by Horace Loeb on Stack Overflow See other posts from Stack Overflow or by Horace Loeb
Published on 2010-06-15T21:28:00Z Indexed on 2010/06/15 21:52 UTC
Read the original article Hit count: 130

I used to have this buggy Paperclip config:

class Photo < ActiveRecord::Base

  has_attached_file :image, :storage => :s3,
                    :styles => { :medium => "600x600>", :small => "320x320>", :thumb => "100x100#" },
                    :s3_credentials => "#{RAILS_ROOT}/config/s3.yml",
                    :path => "/:style/:filename"
end

This is buggy because two images cannot have the same size and filename. To fix this, I changed the config to:

class Photo < ActiveRecord::Base

  has_attached_file :image, :storage => :s3,
                    :styles => { :medium => "600x600>", :small => "320x320>", :thumb => "100x100#" },
                    :s3_credentials => "#{RAILS_ROOT}/config/s3.yml",
                    :path => "/:style/:id_:filename"
end

Unfortunately this breaks all URLs to attachments I've already created. How can I update those file paths or otherwise get the URLs to work?

© Stack Overflow or respective owner

Related posts about ruby-on-rails

Related posts about attachment