我正在尝试使用载波,雾气和AWS来在Heroku上上传图像。很普遍...我什至已经成功为另一个应用程序设置了它。但是,当我向heroku下达命令时,出现此错误:
运行:耙资产:预编译 耙子流产了! NameError:未初始化的常量CarrierWave :: Storage :: Fog
宝石文件
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: 服务:S3 aws_access_key_id:“密钥” aws_secret_access_key:“密钥” 地区:“ us-east-2” AWS_BUCKET:“存储桶”
在配置初始化程序中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
这是构建日志:
-----> 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
我一直在搜索这个问题,并在stackoverflow上寻找类似的问题,无法解决。我敢肯定这很简单。
答案 0 :(得分:2)
我在各个项目中反复遇到此问题,通常通过在初始化程序中将CarrierWave::Storage::Fog
类定义为空类来解决此问题。
令人惊讶的是,这似乎可行,并且似乎并不干扰Rails加载真实类的能力:
# config/initializers/fix_fog.rb
module CarrierWave; module Storage; class Fog; end; end; end
我已经多次部署了这个since at least February 2016。这似乎不是一个很好的解决方案,我会对替代品感兴趣。
答案 1 :(得分:0)
另一种解决方案:
在config / initializers / fog.rb文件的顶部添加require 'carrierwave/storage/fog'
。