Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use Fog with CarrierWave only in Production

I am using Heroku and S3 with my Rails app. I only have the fog gem installed in production mode because my local computer is a piece of junk. Anyway, it works fine this way and has proven to be the better solution than pulling my hair out to get fog installed locally, but now I have to switch the Uploader file to use localhost and then switch it back to make a commitment.

It would be nice to be able to use file locally and then fog in production mode without manually switching back and forth. Does anyone have any suggestions about how to do this?

Thanks a lot in advance.

like image 541
spitfire109 Avatar asked Jan 06 '13 02:01

spitfire109


1 Answers

This is pretty easy. You have to define it in the configuration file. But don't define the storage in your models as this would override the settings from config file.

# sample config/initializers/carrierwave.rb
CarrierWave.configure do |config|

  if Rails.env.development? || Rails.env.test?
    config.storage = :file
  else
    config.fog_credentials = {
      :provider               => 'AWS',
      :aws_access_key_id      =>  'some_access_key_id',
      :aws_secret_access_key  => 'some_secret_key',
      :region                 => 'eu-west-1'
    }
    config.storage = :fog
    config.fog_directory = 'bucket_name'
  end
end
like image 180
Fa11enAngel Avatar answered Oct 12 '22 11:10

Fa11enAngel