Search code examples
ruby-on-railsherokucarrierwavestaging

Carrierwave storage path management with a staging instance on Heroku


I have two instances of my app in production on Heroku, staging.myapp.com and www.myapp.com, and I am following this workflow: Staging instance on Heroku. As I am using Carrierwave with AWS S3, I would like to know if it is possible to modify the storage path in order to specify each instance, e.g.:

def store_dir
  instance = "staging" | "production"       
  #{instance}/#{model.class.to_s.underscore}/#{mounted_as}/#{model.id}
end

Solution

  • I keep my assets in seperate buckets and do it like this;

    config.fog_directory  = "myappname-#{Rails.env}-assets"
    

    so it will use a bucket name myappname-production-assets or myappname-staging-assets.

    in my carrierwave initializer. Make sure you read 'Configuring Carrierwave' on https://github.com/jnicklas/carrierwave and 'Using Amazon S3'