Skip to content

Instantly share code, notes, and snippets.

@thechrisoshow
Created February 2, 2012 10:57
Show Gist options
  • Save thechrisoshow/1722888 to your computer and use it in GitHub Desktop.
Save thechrisoshow/1722888 to your computer and use it in GitHub Desktop.
Have a failsafe s3 url for paperclip attachments
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