Created
February 2, 2012 10:57
-
-
Save thechrisoshow/1722888 to your computer and use it in GitHub Desktop.
Have a failsafe s3 url for paperclip attachments
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module Paperclip | |
class Attachment | |
def url_with_failsafe style = default_style, include_updated_timestamp = true | |
unadorned_url = url_without_failsafe(style, include_updated_timestamp) | |
if in_bucket_substitution_environment? && !exists? | |
unadorned_url.sub(/\/#{bucket_name}\//, '/specle-production/') | |
else | |
unadorned_url | |
end | |
end | |
alias_method_chain :url, :failsafe | |
private | |
def in_bucket_substitution_environment? | |
Rails.env.development? || Rails.env.staging? || Rails.env.qa? | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment