简体   繁体   English

使用Capistrano将Rails应用程序部署到服务器上时,“未初始化的恒定CarrierWave”

[英]“uninitialized constant CarrierWave” on deploy of Rails app to server with Capistrano

I have a Rails app that works perfectly well locally on Mac OS X using Ruby 1.9.3 and Rails 3.2.13. 我有一个Rails应用程序,它在使用Ruby 1.9.3和Rails 3.2.13的Mac OS X上可以很好地在本地运行。 This has been deployed to my Ubuntu virtual server (nginx / unicorn) using Capistrano and has been working fine. 这已使用Capistrano部署到了我的Ubuntu虚拟服务器(nginx / unicorn),并且运行良好。

The problem came when I installed the CarrierWave gem with RMagick. 当我用RMagick安装CarrierWave gem时,问题就来了。 These were added to the gemfile and worked perfectly well locally, but on deploying to the server I get a 500 error every time. 这些已添加到gemfile并在本地完美运行,但是在部署到服务器时,每次都会出现500错误。

A brief extract from the unicorn.log on the server: 服务器上unicorn.log的简要摘录:

E, [2013-06-28T12:04:05.937845 #2758] ERROR -- : reaped #<Process::Status: pid 23786 exit 1> worker=0
I, [2013-06-28T12:04:05.939517 #2758]  INFO -- : worker=0 spawning...
I, [2013-06-28T12:04:05.968225 #23793]  INFO -- : worker=0 spawned pid=23793
I, [2013-06-28T12:04:05.969959 #23793]  INFO -- : Refreshing Gem list
E, [2013-06-28T12:04:59.669504 #23793] ERROR -- : uninitialized constant CarrierWave (NameError)
/home/deployer/apps/panto/releases/20130628115346/app/uploaders/image_uploader.rb:3:in `<top (required)>'
/home/deployer/apps/panto/releases/20130628115346/app/models/picture.rb:4:in `<class:Picture>'
/home/deployer/apps/panto/releases/20130628115346/app/models/picture.rb:1:in `<top (required)>'

The file referred to in the "uninitialized constant" error is my CarrierWave uploader class, created by CarrierWave's own generator, which begins: “未初始化的常量”错误中提到的文件是我的CarrierWave上传器类,该类由CarrierWave自己的生成器创建,该类开始:

# encoding: utf-8

class ImageUploader < CarrierWave::Uploader::Base

  # Include RMagick or MiniMagick support:
  include CarrierWave::RMagick
  # include CarrierWave::MiniMagick

  # Include the Sprockets helpers for Rails 3.1+ asset pipeline compatibility:
  include Sprockets::Helpers::RailsHelper
  include Sprockets::Helpers::IsolatedHelper

The error therefore relates to the inheritance of the main CarrierWave class. 因此,该错误与主CarrierWave类的继承有关。

Extract from Gemfile: 从Gemfile中提取:

gem 'jquery-rails'
gem 'simple_form'
gem 'country_select'
gem 'carrierwave'
gem 'rmagick'

And from Gemfile.lock: 从Gemfile.lock:

carrierwave (0.8.0)
  activemodel (>= 3.2.0)
  activesupport (>= 3.2.0)
...
rmagick (2.13.2)

These files are identical in my git repository and on the server. 这些文件在我的git存储库和服务器上都是相同的。 This appears to be sufficient for my locally-run app to find CarrierWave, but not for the server version. 对于本地运行的应用程序来说,这似乎足以找到CarrierWave,但对于服务器版本而言,还不够。

Capistrano runs bundle:install and restarts the server on deployment, but I've tried doing both manually as well without any change. Capistrano运行bundle:install并在部署时重新启动服务器,但是我尝试过手动进行这两项操作,而无需进行任何更改。

I've seen a few similar problems reported online, but none with a solution that seems to relate to this—some say it has nothing to do with CarrierWave but don't say what it does have to do with. 我已经在网上看到了一些类似的问题报告,但是都没有一个与此相关的解决方案-有人说它与CarrierWave没有关系,但没有说与它有什么关系。

Can anyone give me any pointers please while I cap deploy:rollback again? 在我再次cap deploy:rollback时,谁能给我任何指示?

Thanks. 谢谢。

Latest update: 最新更新:

I have the app up and running on the server. 我已经在服务器上运行了该应用程序。 While require 'carrierwave' didn't work in the application.rb file, logging into the server as the deploy user, navigating into the app directory, opening a rails console using RAILS_ENV=production bundle exec rails c and then typing require 'carrierwave' seems to have made it work. require 'carrierwave'在application.rb文件中不起作用时,以部署用户身份登录服务器,导航至app目录,使用RAILS_ENV=production bundle exec rails c打开Rails控制台,然后键入require 'carrierwave'似乎已经成功了。

I'm not marking this as answered just yet as I suspect it may all stop again at the next deploy, but it perhaps narrows down the problem. 我尚未将其标记为已回答,因为我怀疑它可能会在下一次部署中再次停止,但可能会缩小问题范围。

It looks like this could be related to the require order of the gems. 看起来这可能与宝石的需求顺序有关。 See this stackoverflow question for context. 有关上下文,请参见此stackoverflow问题 Some people seem to hack around it with an explicit require in application.rb (like this ) but hopefully changing the order in the Gemfile to: 有些人似乎周围破解有明确要求在application.rb中(像这样 ),但希望改变才能在Gemfile中来:

gem 'rmagick'
gem 'carrierwave'

should fix it. 应该修复它。

Also this might help with making sure RMagick is installed correctly on your server. 另外, 可能有助于确保在服务器上正确安装了RMagick。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM