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.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With