Set the configuration: add RACK_ENV = stage in your intermediate field, and then in your code you can specify the bucket depending on the environment. For example:
if Rails.env.production? has_attached_file :photo, :styles => ..., :path => ..., :storage => :s3, :bucket => 'your_prod_bucket', :s3_credentials => { :access_key_id => ENV['S3_KEY'], :secret_access_key => ENV['S3_SECRET'] } else has_attached_file :photo, :styles => ..., :path => ..., :storage => :s3, :bucket => 'your_staging_bucket', :s3_credentials => { :access_key_id => ENV['S3_KEY'], :secret_access_key => ENV['S3_SECRET'] } end
This heroku post also seems to suggest that you can achieve this simply by using different s3 credentials for production and production. I assume that you will need to do some configuration on the Amazon side. In any case, see if this helps. http://devcenter.heroku.com/articles/config-vars
Kevin tsoi
source share