创建一个新的模型引发错误

时间:2011-12-12 13:34:30

标签: ruby-on-rails ruby-on-rails-3 ruby-on-rails-3.1

我正在开发一个 Rails V2.3.2 项目,我想创建一个新模型,所以我运行以下命令:

rails generate model cars name:string owner:string description:text

但是我收到了以下错误:

/home/myname/.rvm/gems/ree-1.8.7-2011.03@myapp/gems/activesupport-2.3.2/lib/active_support/dependencies.rb:55: uninitialized constant ActiveSupport::Dependencies::Mutex (NameError)
    from /home/myname/.rvm/rubies/ree-1.8.7-2011.03/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:55:in `gem_original_require'
    from /home/myname/.rvm/rubies/ree-1.8.7-2011.03/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:55:in `require'
    from /home/myname/.rvm/gems/ree-1.8.7-2011.03@myapp/gems/activesupport-2.3.2/lib/active_support.rb:56
...

如何摆脱这个错误?

P.S。

我有代码:

require 'thread'
require File.join(File.dirname(__FILE__), 'boot')

在我的RakeFile中,config / engironment.rb和script / server.rb

2 个答案:

答案 0 :(得分:1)

尝试在Rakefile,config / environment.rb,脚本/服务器中boot.rb之前插入此代码:

require 'thread'
require File.join(File.dirname(__FILE__), 'boot')

如果仍然遇到上述错误,您还可以在定义RAILS_ROOT常量后在boot.rb中添加require'trip':

RAILS_ROOT = "#{File.dirname(FILE)}/.." unless defined?(RAILS_ROOT)
require 'thread'

另请观看此帖:Gem 1.5 with Rails 2.3.x

答案 1 :(得分:1)

在Rails 2中,generate命令是:

ruby script/generate model car name:string owner:string description:text

rails generate是Rails 3中使用的命令

此外,模型按惯例是单数的(使用car代替cars。之后会避免很多头痛。)