Intellipaat Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in AWS by (19.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 (44.4k 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

Related questions

Want to get 50% Hike on your Salary?

Learn how we helped 50,000+ professionals like you !

31k questions

32.8k answers

501 comments

693 users

Browse Categories

...