0 votes
1 view
in AWS by (18.1k points)

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?

1 Answer

0 votes
by (42.2k points)

You can solve it by defining it in the configuration file. But don't define the storage in models, because it will override the setting in the 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

...