Skip to content

Instantly share code, notes, and snippets.

@ckdake
Created November 3, 2011 18:38
Show Gist options
  • Save ckdake/1337372 to your computer and use it in GitHub Desktop.
Save ckdake/1337372 to your computer and use it in GitHub Desktop.
Rails 3.1 Assets on S3 with HTTPS
if Rails.env.production?
CarrierWave.configure do |config|
config.fog_credentials = {
provider: 'AWS',
aws_access_key_id: ENV['AWS_ACCESS_KEY'],
aws_secret_access_key: ENV['AWS_ACCESS_SECRET'],
region: 'us-east-1'
}
config.fog_host = "//#{ENV['MEDIA_BUCKET']}.s3.amazonaws.com"
config.fog_directory = ENV['MEDIA_BUCKET']
config.fog_attributes = {'Cache-Control' => 'max-age=315576000'}
config.storage = :fog
end
elsif Rails.env.development?
CarrierWave.configure do |config|
config.storage = :file
config.enable_processing = false
end
elsif Rails.env.test? or Rails.env.cucumber?
CarrierWave.configure do |config|
config.storage = :file
config.enable_processing = false
end
end
ENV['AWS_ACCESS_KEY'] = 'XXX'
ENV['AWS_ACCESS_SECRET'] = 'XXXXXX'
ENV['AWS_BUCKET'] = 'bucket-example-com'
desc "deploys to heroku after uploading assets to S3"
task deploy: [:environment, 'assets:precompile'] do
puts `git push heroku`
puts `rake assets:clean`
end
gem 'fog' # Storage on S3 for carrierwave
gem 'rmagick' # Resizes images and makes thumbnails
gem 'carrierwave' # Image attachments, newer version doesn't work with local files preview hack
gem 'asset_sync' # Syncs assets to S3
config.action_controller.asset_host = "//#{ENV['AWS_BUCKET']}.s3.amazonaws.com"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment