Ruby on Rails - Heroku部署中未初始化的常量CarrierWave(NameError)

时间:2017-07-11 15:33:36

标签: ruby-on-rails heroku imagemagick carrierwave

我正在尝试将应用程序从cloud9 Rails实例部署到Heroku。部署成功完成,但应用程序在启动时崩溃。此外,无法加载Heroku rails控制台 - 请参阅下面的错误。我是R的新手。

我在本地机箱和cloud9上遇到了imagemagick的问题,直到我安装完毕。不知道如何在Heroku实例上实现这一点,如果这确实是我的问题。欢迎提出想法,建议和问题。

$ heroku run rails console
Running rails console on ⬢ bttttt-xxxxxxxs-888888... up, run.9920 (Free)
/app/app/uploaders/image_uploader.rb:1:in `<top (required)>': uninitialized constant CarrierWave (NameError)
    from /app/vendor/bundle/ruby/2.3.0/gems/activesupport-5.0.4/lib/active_support/dependencies/interlock.rb:12:in `block in loading'
    from /app/vendor/bundle/ruby/2.3.0/gems/activesupport-5.0.4/lib/active_support/concurrency/share_lock.rb:150:in `exclusive'
    from /app/vendor/bundle/ruby/2.3.0/gems/activesupport-5.0.4/lib/active_support/dependencies/interlock.rb:11:in `loading'
    from /app/app/models/restaurant.rb:2:in `<class:Restaurant>'
    from /app/app/models/restaurant.rb:1:in `<top (required)>'
    from /app/vendor/bundle/ruby/2.3.0/gems/activesupport-5.0.4/lib/active_support/dependencies/interlock.rb:12:in `block in loading'
    from /app/vendor/bundle/ruby/2.3.0/gems/activesupport-5.0.4/lib/active_support/concurrency/share_lock.rb:150:in `exclusive'
    from /app/vendor/bundle/ruby/2.3.0/gems/activesupport-5.0.4/lib/active_support/dependencies/interlock.rb:11:in `loading'
    from /app/vendor/bundle/ruby/2.3.0/gems/railties-5.0.4/lib/rails/engine.rb:476:in `block (2 levels) in eager_load!'
    from /app/vendor/bundle/ruby/2.3.0/gems/railties-5.0.4/lib/rails/engine.rb:475:in `each'
    from /app/vendor/bundle/ruby/2.3.0/gems/railties-5.0.4/lib/rails/engine.rb:475:in `block in eager_load!'
    from /app/vendor/bundle/ruby/2.3.0/gems/railties-5.0.4/lib/rails/engine.rb:473:in `each'
    from /app/vendor/bundle/ruby/2.3.0/gems/railties-5.0.4/lib/rails/engine.rb:473:in `eager_load!'
    from /app/vendor/bundle/ruby/2.3.0/gems/railties-5.0.4/lib/rails/engine.rb:354:in `eager_load!'
    from /app/vendor/bundle/ruby/2.3.0/gems/railties-5.0.4/lib/rails/application/finisher.rb:59:in `each'
    from /app/vendor/bundle/ruby/2.3.0/gems/railties-5.0.4/lib/rails/application/finisher.rb:59:in `block in <module:Finisher>'
    from /app/vendor/bundle/ruby/2.3.0/gems/railties-5.0.4/lib/rails/initializable.rb:30:in `instance_exec'
    from /app/vendor/bundle/ruby/2.3.0/gems/railties-5.0.4/lib/rails/initializable.rb:30:in `run'
    from /app/vendor/bundle/ruby/2.3.0/gems/railties-5.0.4/lib/rails/initializable.rb:55:in `block in run_initializers'
    from /app/vendor/ruby-2.3.4/lib/ruby/2.3.0/tsort.rb:228:in `block in tsort_each'
    from /app/vendor/ruby-2.3.4/lib/ruby/2.3.0/tsort.rb:350:in `block (2 levels) in each_strongly_connected_component'
    from /app/vendor/ruby-2.3.4/lib/ruby/2.3.0/tsort.rb:431:in `each_strongly_connected_component_from'
    from /app/vendor/ruby-2.3.4/lib/ruby/2.3.0/tsort.rb:349:in `block in each_strongly_connected_component'
    from /app/vendor/ruby-2.3.4/lib/ruby/2.3.0/tsort.rb:347:in `each'
    from /app/vendor/ruby-2.3.4/lib/ruby/2.3.0/tsort.rb:347:in `call'
    from /app/vendor/ruby-2.3.4/lib/ruby/2.3.0/tsort.rb:347:in `each_strongly_connected_component'
    from /app/vendor/ruby-2.3.4/lib/ruby/2.3.0/tsort.rb:226:in `tsort_each'
    from /app/vendor/ruby-2.3.4/lib/ruby/2.3.0/tsort.rb:205:in `tsort_each'
    from /app/vendor/bundle/ruby/2.3.0/gems/railties-5.0.4/lib/rails/initializable.rb:54:in `run_initializers'
    from /app/vendor/bundle/ruby/2.3.0/gems/railties-5.0.4/lib/rails/application.rb:352:in `initialize!'
    from /app/config/environment.rb:5:in `<top (required)>'
    from /app/vendor/bundle/ruby/2.3.0/gems/railties-5.0.4/lib/rails/application.rb:328:in `require'
    from /app/vendor/bundle/ruby/2.3.0/gems/railties-5.0.4/lib/rails/application.rb:328:in `require_environment!'
    from /app/vendor/bundle/ruby/2.3.0/gems/railties-5.0.4/lib/rails/commands/commands_tasks.rb:157:in `require_application_and_environment!'
    from /app/vendor/bundle/ruby/2.3.0/gems/railties-5.0.4/lib/rails/commands/commands_tasks.rb:77:in `console'
    from /app/vendor/bundle/ruby/2.3.0/gems/railties-5.0.4/lib/rails/commands/commands_tasks.rb:49:in `run_command!'
    from /app/vendor/bundle/ruby/2.3.0/gems/railties-5.0.4/lib/rails/commands.rb:18:in `<top (required)>'
    from /app/bin/rails:9:in `require'
    from /app/bin/rails:9:in `<main>'

Gemfile代码 -

source 'https://rubygems.org'

git_source(:github) do |repo_name|
  repo_name = "#{repo_name}/#{repo_name}" unless repo_name.include?("/")
  "https://github.com/#{repo_name}.git"
end

# Bundle edge Rails instead: gem 'rails', github: 'rails/rails'
gem 'rails', '~> 5.0.1'
# Use sqlite3 as the database for Active Record
#gem 'sqlite3'
# Use Puma as the app server
gem 'puma', '~> 3.0'
# Use SCSS for stylesheets
gem 'sass-rails', '~> 5.0'
# Use Uglifier as compressor for JavaScript assets
gem 'uglifier', '>= 1.3.0'
# Use CoffeeScript for .coffee assets and views
gem 'coffee-rails', '~> 4.2'
# See https://github.com/rails/execjs#readme for more supported runtimes
# gem 'therubyracer', platforms: :ruby

# Use jquery as the JavaScript library
gem 'jquery-rails'
# Turbolinks makes navigating your web application faster. Read more: https://github.com/turbolinks/turbolinks
gem 'turbolinks', '~> 5'
# 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', '~> 3.0'
# Use ActiveModel has_secure_password
gem 'bcrypt', '~> 3.1.7'

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

group :development, :test do
  # Call 'byebug' anywhere in the code to stop execution and get a debugger console
  gem 'byebug', platform: :mri
  gem 'sqlite3'
end

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

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

group :production do
  gem 'pg', '0.20.0'
end

1 个答案:

答案 0 :(得分:0)

  

未初始化的常量CarrierWave(NameError)

您已将gem 'carrierwave'置于group :development下,以便宝石未捆绑在制作中。这就是错误的原因。

<强>解决方案:

将其移至外部 development

source 'https://rubygems.org'

git_source(:github) do |repo_name|
  repo_name = "#{repo_name}/#{repo_name}" unless repo_name.include?("/")
  "https://github.com/#{repo_name}.git"
end

# Bundle edge Rails instead: gem 'rails', github: 'rails/rails'
gem 'rails', '~> 5.0.1'
# Use sqlite3 as the database for Active Record
#gem 'sqlite3'
# Use Puma as the app server
gem 'puma', '~> 3.0'
# Use SCSS for stylesheets
gem 'sass-rails', '~> 5.0'
# Use Uglifier as compressor for JavaScript assets
gem 'uglifier', '>= 1.3.0'
# Use CoffeeScript for .coffee assets and views
gem 'coffee-rails', '~> 4.2'
# See https://github.com/rails/execjs#readme for more supported runtimes
# gem 'therubyracer', platforms: :ruby

# Use jquery as the JavaScript library
gem 'jquery-rails'
# Turbolinks makes navigating your web application faster. Read more: https://github.com/turbolinks/turbolinks
gem 'turbolinks', '~> 5'
# 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', '~> 3.0'
# Use ActiveModel has_secure_password
gem 'bcrypt', '~> 3.1.7'
gem 'carrierwave'
# Use Capistrano for deployment
# gem 'capistrano-rails', group: :development

group :development, :test do
  # Call 'byebug' anywhere in the code to stop execution and get a debugger console
  gem 'byebug', platform: :mri
  gem 'sqlite3'
end

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

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

group :production do
  gem 'pg', '0.20.0'
end

将其添加到developmentproduction

group :development, :production do
  gem 'carrierwave'
end

最后运行bundle install