Skip to content

Instantly share code, notes, and snippets.

@darrenboyd
Created February 16, 2015 19:31
Show Gist options
  • Save darrenboyd/feb2bc38f46a88e44b8d to your computer and use it in GitHub Desktop.
Save darrenboyd/feb2bc38f46a88e44b8d to your computer and use it in GitHub Desktop.
Setup carrierwave in Rails with just fog-aws.
# inside application.rb...
class Application < Rails::Application
# TODO Stop-gap workaround to carrierwave doing "require 'fog'"
# This let's us get ./lib in the load path, where our own
# fog.rb is loaded for carrierwave, but we've already loaded
# fog-aws, which is all we need anyway.
config.before_configuration do
require 'carrierwave'
end
# ... the rest of your config ...
end
# config/initializers/carrierwave.rb
require 'fog/aws'
CarrierWave.configure do |config|
# ... your usual configuration ...
end
# lib/fog.rb
module Fog
# This file only exists so carrierwave has
# something to require.
end
# your Gemfile should look something like...
gem 'fog-aws', require: false # or require: 'fog/aws'
# avoid having carrierwave loading during bundler
# setup. We need to get ./lib in the load_path first.
gem 'carrierwave', require: false
@gugl
Copy link

gugl commented Oct 24, 2018

Update: Newer versions of carrierwave have support to set the fog_provider in the config.
Therefore its now enough to add

config.fog_provider = 'fog/aws'

to your carrierwave config as described in the carrierwave readme

@jasonfine
Copy link

@gugl The docs don't mention that

@gugl
Copy link

gugl commented Jan 10, 2020

@jasonfine You're right, thanks for pointing that out. It seems that fog_provider was deprecated in carrierwave 2.0.0 according to https://github.com/carrierwaveuploader/carrierwave/blob/f81bb4d90c610c4e5d68c2057ab977620d7089a1/CHANGELOG.md#deprecated

"...just adding fog providers to Gemfile will load them" in carrierwave >= 2.0

Current solution in readme: https://github.com/carrierwaveuploader/carrierwave#using-amazon-s3

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment