Skip to content

Instantly share code, notes, and snippets.

@Hampei
Created February 7, 2012 13:38
Show Gist options
  • Save Hampei/1759709 to your computer and use it in GitHub Desktop.
Save Hampei/1759709 to your computer and use it in GitHub Desktop.
interpolation for the url when storing paperclip attachments on s3 that works independent of where your bucket is located.
# normally paperclip uses the server/bucket/location format, but that breaks when you have a eu bucket.
# This one works for all buckets.
# put in an initializer (or somewhere else) and add this to has_attached_file params
# :url => ':s3_url',
Paperclip.interpolates(:s3_url) { |attachment, style|
"#{attachment.s3_protocol}://#{attachment.bucket_name}.s3.amazonaws.com/#{attachment.path(style).gsub(%r{^/}, "")}"
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment