ruby-on-railsamazon-web-servicesherokucarrierwavefog

NameError: uninitialized constant CarrierWave::Storage::Fog, heroku


I am trying to use carrierwave, fog and AWS for my image uploading on Heroku. Pretty common...I even have it set up successfully for another app. However when I delpoy to heroku I'm getting this error:

Running: rake assets:precompile rake aborted! NameError: uninitialized constant CarrierWave::Storage::Fog

Gemfile

source 'https://rubygems.org'
git_source(:github) { |repo| "https://github.com/#{repo}.git" }

ruby '2.3.7'

# Bundle edge Rails instead: gem 'rails', github: 'rails/rails'
gem 'rails', '~> 5.2.1'
# Use postgresql as the database for Active Record
gem 'pg', '>= 0.18', '< 2.0'
# Use Puma as the app server
gem 'puma', '~> 3.11'
# Use SCSS for stylesheets
gem 'sass-rails', '~> 5.0'
# Use Uglifier as compressor for JavaScript assets
gem 'uglifier', '>= 1.3.0'
# See https://github.com/rails/execjs#readme for more supported runtimes
# gem 'mini_racer', platforms: :ruby

# Use CoffeeScript for .coffee assets and views
gem 'coffee-rails', '~> 4.2'
# Turbolinks makes navigating your web application faster. Read more: https://github.com/turbolinks/turbolinks
# Build JSON APIs with ease. Read more: https://github.com/rails/jbuilder
gem 'jbuilder', '~> 2.5'
# Use Redis adapter to run Action Cable in production
# gem 'redis', '~> 4.0'
# Use ActiveModel has_secure_password
# gem 'bcrypt', '~> 3.1.7'
gem 'devise'
gem 'tinymce-rails-imageupload', github: 'PerfectlyNormal/tinymce-rails-imageupload'

# Use ActiveStorage variant
 gem 'mini_magick'
 gem 'carrierwave'
 gem 'fog' 
 gem 'figaro'


 gem 'will_paginate', '~> 3.1.0'
 gem 'bootstrap'
 gem 'jquery-rails'
 gem 'mini_racer'

 gem 'stripe'
 gem 'aws-sdk-s3', require: false


# Use Capistrano for deployment
# gem 'capistrano-rails', group: :development

# Reduces boot times through caching; required in config/boot.rb
gem 'bootsnap', '>= 1.1.0', require: false

group :development, :test do
  # Call 'byebug' anywhere in the code to stop execution and get a debugger console
  gem 'byebug', platforms: [:mri, :mingw, :x64_mingw]
end

group :development do
  # Access an interactive console on exception pages or by calling 'console' anywhere in the code.
  gem 'web-console', '>= 3.3.0'
  gem 'listen', '>= 3.0.5', '< 3.2'
  # Spring speeds up development by keeping your application running in the background. Read more: https://github.com/rails/spring
  gem 'spring'
  gem 'spring-watcher-listen', '~> 2.0.0'
end

group :test do
  # Adds support for Capybara system testing and selenium driver
  gem 'capybara', '>= 2.15'
  gem 'selenium-webdriver'
  # Easy installation and use of chromedriver to run system tests with Chrome
  gem 'chromedriver-helper'
end

# Windows does not include zoneinfo files, so bundle the tzinfo-data gem
gem 'tzinfo-data', platforms: [:mingw, :mswin, :x64_mingw, :jruby]

application.yml

amazon: service: S3 aws_access_key_id: "key" aws_secret_access_key: "key" region: "us-east-2" AWS_BUCKET: "bucket"

in the config initializers... fog.rb

CarrierWave.configure do |config|
  config.fog_credentials = {
    provider: 'AWS',
    aws_access_key_id: 'aws_access_key_id',
    aws_secret_access_key: 'aws_secret_access_key',
    region: 'us-east-2'
  }

      config.fog_directory = 'books4reviews'

  if Rails.env.development? || Rails.env.test?
    CarrierWave.configure do |config|
      config.storage = :file
    end
  end

  # Use AWS storage if in production
  if Rails.env.production?
    CarrierWave.configure do |config|
      config.storage = :fog
    end
  end
end

Here's the build log:

-----> Detecting rake tasks
-----> Preparing app for Rails asset pipeline
       Running: rake assets:precompile
       rake aborted!
       NameError: uninitialized constant CarrierWave::Storage::Fog
       /tmp/build_cc315cc16be89c43f2c799ba61fa4e8e/vendor/bundle/ruby/2.3.0/gems/carrierwave-1.2.3/lib/carrierwave/uploader/configuration.rb:78:in `eval'
       /tmp/build_cc315cc16be89c43f2c799ba61fa4e8e/vendor/bundle/ruby/2.3.0/gems/bootsnap-1.3.2/lib/bootsnap/load_path_cache/core_ext/active_support.rb:16:in `allow_bootsnap_retry'
       /tmp/build_cc315cc16be89c43f2c799ba61fa4e8e/vendor/bundle/ruby/2.3.0/gems/bootsnap-1.3.2/lib/bootsnap/load_path_cache/core_ext/active_support.rb:57:in `load_missing_constant'
       (eval):1:in `storage'
       /tmp/build_cc315cc16be89c43f2c799ba61fa4e8e/vendor/bundle/ruby/2.3.0/gems/carrierwave-1.2.3/lib/carrierwave/uploader/configuration.rb:78:in `eval'
       /tmp/build_cc315cc16be89c43f2c799ba61fa4e8e/vendor/bundle/ruby/2.3.0/gems/carrierwave-1.2.3/lib/carrierwave/uploader/configuration.rb:78:in `storage'
       /tmp/build_cc315cc16be89c43f2c799ba61fa4e8e/app/uploaders/avatar_uploader.rb:7:in `<class:AvatarUploader>'
       /tmp/build_cc315cc16be89c43f2c799ba61fa4e8e/app/uploaders/avatar_uploader.rb:1:in `<main>'
       /tmp/build_cc315cc16be89c43f2c799ba61fa4e8e/vendor/bundle/ruby/2.3.0/gems/bootsnap-1.3.2/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:21:in `require'
       /tmp/build_cc315cc16be89c43f2c799ba61fa4e8e/vendor/bundle/ruby/2.3.0/gems/bootsnap-1.3.2/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:21:in `block in require_with_bootsnap_lfi'
       /tmp/build_cc315cc16be89c43f2c799ba61fa4e8e/vendor/bundle/ruby/2.3.0/gems/bootsnap-1.3.2/lib/bootsnap/load_path_cache/loaded_features_index.rb:65:in `register'
       /tmp/build_cc315cc16be89c43f2c799ba61fa4e8e/vendor/bundle/ruby/2.3.0/gems/bootsnap-1.3.2/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:20:in `require_with_bootsnap_lfi'
       /tmp/build_cc315cc16be89c43f2c799ba61fa4e8e/vendor/bundle/ruby/2.3.0/gems/bootsnap-1.3.2/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:29:in `require'
       /tmp/build_cc315cc16be89c43f2c799ba61fa4e8e/vendor/bundle/ruby/2.3.0/gems/activesupport-5.2.1/lib/active_support/dependencies/interlock.rb:14:in `block in loading'
       /tmp/build_cc315cc16be89c43f2c799ba61fa4e8e/vendor/bundle/ruby/2.3.0/gems/activesupport-5.2.1/lib/active_support/concurrency/share_lock.rb:151:in `exclusive'
       /tmp/build_cc315cc16be89c43f2c799ba61fa4e8e/vendor/bundle/ruby/2.3.0/gems/activesupport-5.2.1/lib/active_support/dependencies/interlock.rb:13:in `loading'
       /tmp/build_cc315cc16be89c43f2c799ba61fa4e8e/vendor/bundle/ruby/2.3.0/gems/bootsnap-1.3.2/lib/bootsnap/load_path_cache/core_ext/active_support.rb:46:in `block in require_or_load'
       /tmp/build_cc315cc16be89c43f2c799ba61fa4e8e/vendor/bundle/ruby/2.3.0/gems/bootsnap-1.3.2/lib/bootsnap/load_path_cache/core_ext/active_support.rb:16:in `allow_bootsnap_retry'
       /tmp/build_cc315cc16be89c43f2c799ba61fa4e8e/vendor/bundle/ruby/2.3.0/gems/bootsnap-1.3.2/lib/bootsnap/load_path_cache/core_ext/active_support.rb:45:in `require_or_load'
       /tmp/build_cc315cc16be89c43f2c799ba61fa4e8e/vendor/bundle/ruby/2.3.0/gems/bootsnap-1.3.2/lib/bootsnap/load_path_cache/core_ext/active_support.rb:58:in `block in load_missing_constant'
       /tmp/build_cc315cc16be89c43f2c799ba61fa4e8e/vendor/bundle/ruby/2.3.0/gems/bootsnap-1.3.2/lib/bootsnap/load_path_cache/core_ext/active_support.rb:16:in `allow_bootsnap_retry'
       /tmp/build_cc315cc16be89c43f2c799ba61fa4e8e/vendor/bundle/ruby/2.3.0/gems/bootsnap-1.3.2/lib/bootsnap/load_path_cache/core_ext/active_support.rb:57:in `load_missing_constant'
       /tmp/build_cc315cc16be89c43f2c799ba61fa4e8e/vendor/bundle/ruby/2.3.0/gems/bootsnap-1.3.2/lib/bootsnap/load_path_cache/core_ext/active_support.rb:58:in `block in load_missing_constant'
       /tmp/build_cc315cc16be89c43f2c799ba61fa4e8e/vendor/bundle/ruby/2.3.0/gems/bootsnap-1.3.2/lib/bootsnap/load_path_cache/core_ext/active_support.rb:16:in `allow_bootsnap_retry'
       /tmp/build_cc315cc16be89c43f2c799ba61fa4e8e/vendor/bundle/ruby/2.3.0/gems/bootsnap-1.3.2/lib/bootsnap/load_path_cache/core_ext/active_support.rb:57:in `load_missing_constant'
       /tmp/build_cc315cc16be89c43f2c799ba61fa4e8e/app/models/user.rb:2:in `<class:User>'
       /tmp/build_cc315cc16be89c43f2c799ba61fa4e8e/app/models/user.rb:1:in `<main>'
       /tmp/build_cc315cc16be89c43f2c799ba61fa4e8e/vendor/bundle/ruby/2.3.0/gems/bootsnap-1.3.2/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:21:in `require'
       /tmp/build_cc315cc16be89c43f2c799ba61fa4e8e/vendor/bundle/ruby/2.3.0/gems/bootsnap-1.3.2/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:21:in `block in require_with_bootsnap_lfi'
       /tmp/build_cc315cc16be89c43f2c799ba61fa4e8e/vendor/bundle/ruby/2.3.0/gems/bootsnap-1.3.2/lib/bootsnap/load_path_cache/loaded_features_index.rb:65:in `register'
       /tmp/build_cc315cc16be89c43f2c799ba61fa4e8e/vendor/bundle/ruby/2.3.0/gems/bootsnap-1.3.2/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:20:in `require_with_bootsnap_lfi'
       /tmp/build_cc315cc16be89c43f2c799ba61fa4e8e/vendor/bundle/ruby/2.3.0/gems/bootsnap-1.3.2/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:29:in `require'
       /tmp/build_cc315cc16be89c43f2c799ba61fa4e8e/vendor/bundle/ruby/2.3.0/gems/activesupport-5.2.1/lib/active_support/dependencies/interlock.rb:14:in `block in loading'
       /tmp/build_cc315cc16be89c43f2c799ba61fa4e8e/vendor/bundle/ruby/2.3.0/gems/activesupport-5.2.1/lib/active_support/concurrency/share_lock.rb:151:in `exclusive'
       /tmp/build_cc315cc16be89c43f2c799ba61fa4e8e/vendor/bundle/ruby/2.3.0/gems/activesupport-5.2.1/lib/active_support/dependencies/interlock.rb:13:in `loading'
       /tmp/build_cc315cc16be89c43f2c799ba61fa4e8e/vendor/bundle/ruby/2.3.0/gems/bootsnap-1.3.2/lib/bootsnap/load_path_cache/core_ext/active_support.rb:46:in `block in require_or_load'
       /tmp/build_cc315cc16be89c43f2c799ba61fa4e8e/vendor/bundle/ruby/2.3.0/gems/bootsnap-1.3.2/lib/bootsnap/load_path_cache/core_ext/active_support.rb:16:in `allow_bootsnap_retry'
       /tmp/build_cc315cc16be89c43f2c799ba61fa4e8e/vendor/bundle/ruby/2.3.0/gems/bootsnap-1.3.2/lib/bootsnap/load_path_cache/core_ext/active_support.rb:45:in `require_or_load'
       /tmp/build_cc315cc16be89c43f2c799ba61fa4e8e/vendor/bundle/ruby/2.3.0/gems/bootsnap-1.3.2/lib/bootsnap/load_path_cache/core_ext/active_support.rb:58:in `block in load_missing_constant'
       /tmp/build_cc315cc16be89c43f2c799ba61fa4e8e/vendor/bundle/ruby/2.3.0/gems/bootsnap-1.3.2/lib/bootsnap/load_path_cache/core_ext/active_support.rb:16:in `allow_bootsnap_retry'
       /tmp/build_cc315cc16be89c43f2c799ba61fa4e8e/vendor/bundle/ruby/2.3.0/gems/bootsnap-1.3.2/lib/bootsnap/load_path_cache/core_ext/active_support.rb:57:in `load_missing_constant'
       /tmp/build_cc315cc16be89c43f2c799ba61fa4e8e/vendor/bundle/ruby/2.3.0/gems/activesupport-5.2.1/lib/active_support/inflector/methods.rb:283:in `const_get'
       /tmp/build_cc315cc16be89c43f2c799ba61fa4e8e/vendor/bundle/ruby/2.3.0/gems/activesupport-5.2.1/lib/active_support/inflector/methods.rb:283:in `block in constantize'
       /tmp/build_cc315cc16be89c43f2c799ba61fa4e8e/vendor/bundle/ruby/2.3.0/gems/activesupport-5.2.1/lib/active_support/inflector/methods.rb:281:in `each'
       /tmp/build_cc315cc16be89c43f2c799ba61fa4e8e/vendor/bundle/ruby/2.3.0/gems/activesupport-5.2.1/lib/active_support/inflector/methods.rb:281:in `inject'
       /tmp/build_cc315cc16be89c43f2c799ba61fa4e8e/vendor/bundle/ruby/2.3.0/gems/activesupport-5.2.1/lib/active_support/inflector/methods.rb:281:in `constantize'
       /tmp/build_cc315cc16be89c43f2c799ba61fa4e8e/vendor/bundle/ruby/2.3.0/gems/devise-4.5.0/lib/devise.rb:316:in `get'
       /tmp/build_cc315cc16be89c43f2c799ba61fa4e8e/vendor/bundle/ruby/2.3.0/gems/devise-4.5.0/lib/devise/mapping.rb:83:in `to'
       /tmp/build_cc315cc16be89c43f2c799ba61fa4e8e/vendor/bundle/ruby/2.3.0/gems/devise-4.5.0/lib/devise/mapping.rb:78:in `modules'
       /tmp/build_cc315cc16be89c43f2c799ba61fa4e8e/vendor/bundle/ruby/2.3.0/gems/devise-4.5.0/lib/devise/mapping.rb:95:in `routes'
       /tmp/build_cc315cc16be89c43f2c799ba61fa4e8e/vendor/bundle/ruby/2.3.0/gems/devise-4.5.0/lib/devise/mapping.rb:162:in `default_used_route'
       /tmp/build_cc315cc16be89c43f2c799ba61fa4e8e/vendor/bundle/ruby/2.3.0/gems/devise-4.5.0/lib/devise/mapping.rb:72:in `initialize'
       /tmp/build_cc315cc16be89c43f2c799ba61fa4e8e/vendor/bundle/ruby/2.3.0/gems/devise-4.5.0/lib/devise.rb:346:in `new'
       /tmp/build_cc315cc16be89c43f2c799ba61fa4e8e/vendor/bundle/ruby/2.3.0/gems/devise-4.5.0/lib/devise.rb:346:in `add_mapping'
       /tmp/build_cc315cc16be89c43f2c799ba61fa4e8e/vendor/bundle/ruby/2.3.0/gems/devise-4.5.0/lib/devise/rails/routes.rb:243:in `block in devise_for'
       /tmp/build_cc315cc16be89c43f2c799ba61fa4e8e/vendor/bundle/ruby/2.3.0/gems/devise-4.5.0/lib/devise/rails/routes.rb:242:in `each'
       /tmp/build_cc315cc16be89c43f2c799ba61fa4e8e/vendor/bundle/ruby/2.3.0/gems/devise-4.5.0/lib/devise/rails/routes.rb:242:in `devise_for'
       /tmp/build_cc315cc16be89c43f2c799ba61fa4e8e/config/routes.rb:33:in `block in <main>'
       /tmp/build_cc315cc16be89c43f2c799ba61fa4e8e/vendor/bundle/ruby/2.3.0/gems/actionpack-5.2.1/lib/action_dispatch/routing/route_set.rb:432:in `instance_exec'
       /tmp/build_cc315cc16be89c43f2c799ba61fa4e8e/vendor/bundle/ruby/2.3.0/gems/actionpack-5.2.1/lib/action_dispatch/routing/route_set.rb:432:in `eval_block'
       /tmp/build_cc315cc16be89c43f2c799ba61fa4e8e/vendor/bundle/ruby/2.3.0/gems/actionpack-5.2.1/lib/action_dispatch/routing/route_set.rb:414:in `draw'
       /tmp/build_cc315cc16be89c43f2c799ba61fa4e8e/config/routes.rb:1:in `<main>'
       /tmp/build_cc315cc16be89c43f2c799ba61fa4e8e/vendor/bundle/ruby/2.3.0/gems/bootsnap-1.3.2/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:50:in `load'
       /tmp/build_cc315cc16be89c43f2c799ba61fa4e8e/vendor/bundle/ruby/2.3.0/gems/bootsnap-1.3.2/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:50:in `load'
       /tmp/build_cc315cc16be89c43f2c799ba61fa4e8e/vendor/bundle/ruby/2.3.0/gems/railties-5.2.1/lib/rails/application/routes_reloader.rb:41:in `block in load_paths'
       /tmp/build_cc315cc16be89c43f2c799ba61fa4e8e/vendor/bundle/ruby/2.3.0/gems/railties-5.2.1/lib/rails/application/routes_reloader.rb:41:in `each'
       /tmp/build_cc315cc16be89c43f2c799ba61fa4e8e/vendor/bundle/ruby/2.3.0/gems/railties-5.2.1/lib/rails/application/routes_reloader.rb:41:in `load_paths'
       /tmp/build_cc315cc16be89c43f2c799ba61fa4e8e/vendor/bundle/ruby/2.3.0/gems/railties-5.2.1/lib/rails/application/routes_reloader.rb:20:in `reload!'
       /tmp/build_cc315cc16be89c43f2c799ba61fa4e8e/vendor/bundle/ruby/2.3.0/gems/railties-5.2.1/lib/rails/application/routes_reloader.rb:30:in `block in updater'
       /tmp/build_cc315cc16be89c43f2c799ba61fa4e8e/vendor/bundle/ruby/2.3.0/gems/activesupport-5.2.1/lib/active_support/file_update_checker.rb:83:in `execute'
       /tmp/build_cc315cc16be89c43f2c799ba61fa4e8e/vendor/bundle/ruby/2.3.0/gems/railties-5.2.1/lib/rails/application/routes_reloader.rb:10:in `execute'
       /tmp/build_cc315cc16be89c43f2c799ba61fa4e8e/vendor/bundle/ruby/2.3.0/gems/railties-5.2.1/lib/rails/application/finisher.rb:130:in `block in <module:Finisher>'
       /tmp/build_cc315cc16be89c43f2c799ba61fa4e8e/vendor/bundle/ruby/2.3.0/gems/railties-5.2.1/lib/rails/initializable.rb:32:in `instance_exec'
       /tmp/build_cc315cc16be89c43f2c799ba61fa4e8e/vendor/bundle/ruby/2.3.0/gems/railties-5.2.1/lib/rails/initializable.rb:32:in `run'
       /tmp/build_cc315cc16be89c43f2c799ba61fa4e8e/vendor/bundle/ruby/2.3.0/gems/railties-5.2.1/lib/rails/initializable.rb:61:in `block in run_initializers'
       /tmp/build_cc315cc16be89c43f2c799ba61fa4e8e/vendor/bundle/ruby/2.3.0/gems/railties-5.2.1/lib/rails/initializable.rb:60:in `run_initializers'
       /tmp/build_cc315cc16be89c43f2c799ba61fa4e8e/vendor/bundle/ruby/2.3.0/gems/railties-5.2.1/lib/rails/application.rb:361:in `initialize!'
       /tmp/build_cc315cc16be89c43f2c799ba61fa4e8e/config/environment.rb:5:in `<main>'
       /tmp/build_cc315cc16be89c43f2c799ba61fa4e8e/vendor/bundle/ruby/2.3.0/gems/bootsnap-1.3.2/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:21:in `require'
       /tmp/build_cc315cc16be89c43f2c799ba61fa4e8e/vendor/bundle/ruby/2.3.0/gems/bootsnap-1.3.2/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:21:in `block in require_with_bootsnap_lfi'
       /tmp/build_cc315cc16be89c43f2c799ba61fa4e8e/vendor/bundle/ruby/2.3.0/gems/bootsnap-1.3.2/lib/bootsnap/load_path_cache/loaded_features_index.rb:65:in `register'
       /tmp/build_cc315cc16be89c43f2c799ba61fa4e8e/vendor/bundle/ruby/2.3.0/gems/bootsnap-1.3.2/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:20:in `require_with_bootsnap_lfi'
       /tmp/build_cc315cc16be89c43f2c799ba61fa4e8e/vendor/bundle/ruby/2.3.0/gems/bootsnap-1.3.2/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:29:in `require'
       /tmp/build_cc315cc16be89c43f2c799ba61fa4e8e/vendor/bundle/ruby/2.3.0/gems/railties-5.2.1/lib/rails/application.rb:337:in `require_environment!'
       /tmp/build_cc315cc16be89c43f2c799ba61fa4e8e/vendor/bundle/ruby/2.3.0/gems/railties-5.2.1/lib/rails/application.rb:520:in `block in run_tasks_blocks'
       /tmp/build_cc315cc16be89c43f2c799ba61fa4e8e/vendor/bundle/ruby/2.3.0/gems/sprockets-rails-3.2.1/lib/sprockets/rails/task.rb:62:in `block (2 levels) in define'
       /tmp/build_cc315cc16be89c43f2c799ba61fa4e8e/vendor/bundle/ruby/2.3.0/gems/rake-12.3.1/exe/rake:27:in `<top (required)>'
       Tasks: TOP => environment
       (See full trace by running task with --trace)
 !
 !     Precompiling assets failed.
 !
 !     Push rejected, failed to compile Ruby app.
 !     Push failed

I've been googling this and looking at similar questions on stackoverflow and can't figure it out. I'm sure it's something simple.


Solution

  • I've encountered this problem repeatedly across various projects, and I typically fix it by defining the CarrierWave::Storage::Fog class myself, as an empty class, in an initializer.

    Amazingly this seems to work, and it doesn't seem to interfere with Rails' ability to load the real class:

    # config/initializers/fix_fog.rb
    module CarrierWave; module Storage; class Fog; end; end; end
    

    I've deployed this several times, since at least February 2016. It doesn't seem like a great solution, and I'd be interested in alternatives.