启动Rails 2应用程序时,“未初始化的常量Gem”或“Rails”

时间:2011-07-26 06:34:10

标签: ruby-on-rails ruby rvm

我有一个使用Rails 2.3.4的应用程序,我正在尝试运行。无论我如何启动它,使用脚本/控制台或脚本/ ferret_server,它总是归结为同样的错误:

未初始化的恒定宝石

当我在线搜索时,我只发现在Gem类中找到类似问题的人。但就我而言,Gem根本就不存在。

我在Ubuntu上运行Ruby。我尝试使用APT附带的Ruby版本和最近使用RVM的版本。什么都没有帮助。

知道如何导致事情以及如何解决问题?提前谢谢!

根据评论者的要求提供一些额外的细节:

ruby -v的输出:

ruby 1.8.7 (2011-02-18 patchlevel 334) [x86_64-linux], MBARI 0x6770, Ruby Enterprise Edition 2011.03

gem -v的输出:

1.8.6

调用ruby script/console输出类似错误(已编辑):

Loading development environment (Rails 2.3.4)
/var/www/sites/example.com/releases/20110726061310/config/environment.rb:12:NameError: uninitialized constant Gem
/usr/local/rvm/rubies/ree-1.8.7-2011.03/lib/ruby/1.8/irb/init.rb:254:in `require': no such file to load -- console_app (LoadError)
        from /usr/local/rvm/rubies/ree-1.8.7-2011.03/lib/ruby/1.8/irb/init.rb:254:in `load_modules'
        from /usr/local/rvm/rubies/ree-1.8.7-2011.03/lib/ruby/1.8/irb/init.rb:252:in `each'
        from /usr/local/rvm/rubies/ree-1.8.7-2011.03/lib/ruby/1.8/irb/init.rb:252:in `load_modules'
        from /usr/local/rvm/rubies/ree-1.8.7-2011.03/lib/ruby/1.8/irb/init.rb:21:in `setup'
        from /usr/local/rvm/rubies/ree-1.8.7-2011.03/lib/ruby/1.8/irb.rb:54:in `start'
        from /usr/local/rvm/rubies/ree-1.8.7-2011.03/bin/irb:17

我正在尝试通过命令:

调用Ferret Server以允许Passenger连接到它

ruby --debug script/ferret_server -e production start

输出以下错误:

Exception `NameError' at ./script/../vendor/plugins/acts_as_ferret/lib/../../../../config/environment.rb:12 - uninitialized constant Gem
uninitialized constant Gem

或者,调用bundle exec ruby --debug script/ferret_server -e production start会输出以下错误:

superclass mismatch for class GemDependency

请注意,我在Rails::Initializer.run do |config|的{​​{1}}行上方添加了以下内容:

require 'thread'
if Gem::VERSION >= "1.3.6" 
  module Rails
    class GemDependency
      def requirement
        r = super
        (r == Gem::Requirement.default) ? nil : r
        end
      end
    end
  end
require File.join(File.dirname(__FILE__), 'boot')

删除上面提到的行代替config/environment.rb错误。

1 个答案:

答案 0 :(得分:0)

尝试推杆:

require 'rubygems'

require 'thread'

之后