1

这是我在控制台中得到的堆栈跟踪:

 C:/ruby/lib/ruby/gems/1.8/gems/activesupport-2.3.2/lib/active_support/dependencies.rb:443:in `load_missing_constant': uninitialized constant ActiveRecord (NameError)
    from C:/ruby/lib/ruby/gems/1.8/gems/activesupport-2.3.2/lib/active_support/dependencies.rb:80:in `const_missing'
    from C:/ruby/lib/ruby/gems/1.8/gems/activesupport-2.3.2/lib/active_support/dependencies.rb:92:in `const_missing'
    from C:/Users/rrevi/Documents/Aptana Studio/developer_portal/config/environment.rb:42
    from C:/ruby/lib/ruby/gems/1.8/gems/rails-2.3.2/lib/initializer.rb:111:in `run'
    from C:/Users/rrevi/Documents/Aptana Studio/developer_portal/config/environment.rb:9
    from C:/ruby/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:31:in `gem_original_require'
    from C:/ruby/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:31:in `require'
    from C:/ruby/lib/ruby/gems/1.8/gems/activesupport-2.3.2/lib/active_support/dependencies.rb:156:in `require'
    from C:/ruby/lib/ruby/gems/1.8/gems/activesupport-2.3.2/lib/active_support/dependencies.rb:521:in `new_constants_in'
    from C:/ruby/lib/ruby/gems/1.8/gems/activesupport-2.3.2/lib/active_support/dependencies.rb:156:in `require'
    from C:/ruby/lib/ruby/gems/1.8/gems/rails-2.3.2/lib/commands/server.rb:84
    from C:/ruby/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:31:in `gem_original_require'
    from C:/ruby/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:31:in `require'
    from ./script/server:3
    from -e:2:in `load'
    from -e:2

以前还好。我没有改变环境(我记得)。很奇怪。我在 Windows Vista 机器上运行 RadRails。

4

2 回答 2

0

您正在运行相当过时的 Rails 版本,它说您缺少ActiveRecordgem。

于 2010-07-08T18:55:23.810 回答
0

如果您收到错误消息:

helloworld.rb:3:in `<main>': uninitialized constant ActiveRecord (NameError)

那么这意味着你还没有安装activerecord ruby​​ gem。您需要安装 gem 以便 Aptana 可以找到它,因此您需要了解以下过程:

  1. 列出可远程安装的 gem。
  2. 搜索可远程安装的 gem。
  3. 安装远程 gem。
  4. 验证您的 gem 是否已安装。

阅读所有这些:http ://docs.rubygems.org/read/chapter/2

要纠正上述错误,您必须执行以下操作:

打开命令提示符并在终端中运行以下命令:

#Find out what gems are installed on your computer:
gem query --local

#Take a look at the ActiveRecord gem, see if it is available.
gem query --remote --name-matches activerecord

#Get more info about the gem on the remote server.
gem specification --remote activerecord

#Install your gem:
gem install --remote activerecord

#See if it installed successfully and is in the installed gem list:
gem query --local  

重新启动您的 IDE。需要告诉 Aptana 使用您的 activerecord gem:

require 'active_record';

下面是一些使用 ActiveRecord gem 来查看 Aptana 是否可以找到您的 activerecord gem 的代码:

#Ruby code
require 'active_record'
class Dog < ActiveRecord::Base
  has_many :dog_tags
end
puts "activerecord gem is installed";

这不会产生错误并打印“activerecord gem is installed”;

于 2012-04-26T16:18:45.033 回答