Ruby-on-rails 未初始化的常量 ActiveSupport::Dependencies::Mutex (NameError)

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/5176782/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-03 00:34:45  来源:igfitidea点击:

Uninitialized constant ActiveSupport::Dependencies::Mutex (NameError)

ruby-on-railsrubygemscompatibility

提问by Sokmesa Khiev

When I want to create a Ruby on Rails project, I get the message below.

当我想创建一个 Ruby on Rails 项目时,我收到以下消息。

/usr/lib/ruby/gems/1.8/gems/activesupport-2.3.8/lib/active_support/dependencies.rb:55: uninitialized constant ActiveSupport::Dependencies::Mutex (NameError)
    from /usr/local/lib/site_ruby/1.8/rubygems/custom_require.rb:36:in `gem_original_require'
    from /usr/local/lib/site_ruby/1.8/rubygems/custom_require.rb:36:in `require'
    from /usr/lib/ruby/gems/1.8/gems/activesupport-2.3.8/lib/active_support.rb:57
    from /usr/local/lib/site_ruby/1.8/rubygems/custom_require.rb:36:in `gem_original_require'
    from /usr/local/lib/site_ruby/1.8/rubygems/custom_require.rb:36:in `require'
    from /usr/lib/ruby/gems/1.8/gems/rails-2.3.8/lib/rails_generator.rb:31
    from /usr/local/lib/site_ruby/1.8/rubygems/custom_require.rb:36:in `gem_original_require'
    from /usr/local/lib/site_ruby/1.8/rubygems/custom_require.rb:36:in `require'
    from /usr/lib/ruby/gems/1.8/gems/rails-2.3.8/bin/rails:15
    from /usr/bin/rails:19:in `load'
    from /usr/bin/rails:19

What has gone wrong? How do I to fix it?

出了什么问题?我该如何解决?

采纳答案by John

This is an incompatibility between Rails 2.3.8 and recent versions of RubyGems. Upgrade to the latest 2.3 version (2.3.11 as of today).

这是 Rails 2.3.8 和最新版本的 RubyGems 之间的不兼容。升级到最新的 2.3 版本(截至今天为 2.3.11)。

回答by Aaron

In case you can't upgrade to Ruby on Rails 2.3.11 (and to expand on douglasr's answer), threadmust be required at the top of boot.rb. For example:

如果您无法升级到 Ruby on Rails 2.3.11(并扩展 douglasr 的答案),则thread必须在boot.rb. 例如:

require 'thread'

# Don't change this file!
# Configure your app in config/environment.rb and config/environments/*.rb
...

回答by Gary S. Weaver

I was able to fix this by downgrading RubyGems to 1.5.3, since it happens with RubyGems 1.6.0+ and Rails < 2.3.11:

我能够通过将 RubyGems 降级到 1.5.3 来解决这个问题,因为它发生在 RubyGems 1.6.0+ 和 Rails < 2.3.11 中:

gem update --system 1.5.3

If you had previously downgraded to an even earlier version and want to update to 1.5.3, you might get the following when trying to run that:

如果您之前已降级到更早的版本并希望更新到 1.5.3,则在尝试运行该版本时可能会得到以下信息:

Updating RubyGems
ERROR:  While executing gem ... (RuntimeError)
    No gem names are allowed with the --system option

If you get that error, then update, so that it lets you specify the version, and then downgrade again:

如果您收到该错误,请更新,以便您指定版本,然后再次降级:

gem update --system
gem update --system 1.5.3

回答by douglasr

You can also likely get around this issue by requiring 'thread' in your application as such:

您也可以通过在您的应用程序中要求“线程”来解决这个问题:

require 'thread'

As per the RubyGems 1.6.0 release notes.

根据 RubyGems 1.6.0发行说明

回答by arunagw

If you want to keep your version same like rails will be 2.3.8 and gem version will be latest. You can use this solution Latest gem with Rails2.x. in this some changes in boot.rb file and environment.rb file.

如果你想保持你的版本相同,rails 将是 2.3.8,gem 版本将是最新的。您可以在 Rails2.x 中使用此解决方案最新的 gem。在这个 boot.rb 文件和 environment.rb 文件中的一些变化。

require 'thread' in boot.rb file at the top.

require 'thread' 在顶部的 boot.rb 文件中。

and in environment.rb file add the following code above the initializer block.

并在 environment.rb 文件中在初始化程序块上方添加以下代码。

if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.3.7')
 module Rails
   class GemDependency
     def requirement
       r = super
       (r == Gem::Requirement.default) ? nil : r
     end
   end
 end
end

回答by Tania R

I have faced this problem in many occassions when I try to start an old rails 2.3.5 project after having worked with rails 3>. In my case to solve the problem, I must do a rubygems update to version 1.4.2, this is:

当我在使用 rails 3> 后尝试启动旧的 rails 2.3.5 项目时,我在很多场合都遇到过这个问题。在我的情况下,要解决这个问题,我必须将 ruby​​gems 更新到 1.4.2 版,这是:

sudo gem update --system 1.4.2

回答by thekingoftruth

If you're using Radiant CMS, simply add

如果您使用的是 Radiant CMS,只需添加

require 'thread'

to the top of config/boot.rb.

config/boot.rb.

(Kudos to Aaron's and nathanvda's responses.)

(感谢 Aaron 和 nathanvda 的回应。)

回答by Paul Grayson

As mentioned this occurs when using RubyGems 1.6.0 with Ruby on Rails version earlier than version 3. My app is using Ruby on Rails 2.3.3 vendored into the /vendor of the project.

如前所述,当将 RubyGems 1.6.0 与版本 3 之前的 Ruby on Rails 版本一起使用时,会发生这种情况。我的应用程序使用供应商提供给项目 /vendor 的 Ruby on Rails 2.3.3。

No doubt an upgrade of Ruby on Rails to a newer 2.3.X version may also fix this issue. However, this problem prevents you running Raketo unvendor Ruby on Rails and upgrade it.

毫无疑问,将 Ruby on Rails 升级到更新的 2.3.X 版本也可以解决这个问题。但是,此问题会阻止您运行Rake来卸载 Ruby on Rails 并对其进行升级。

Adding require 'thread' to the top of environment.rb did not fix the issue for me. Adding require 'thread' to /vendor/rails/activesupport/lib/active_support.rb did fix the problem.

将 require 'thread' 添加到 environment.rb 的顶部并没有解决我的问题。将 require 'thread' 添加到 /vendor/rails/activesupport/lib/active_support.rb 确实解决了问题。

回答by Andrew Marshall

Try updating your Ruby on Rails version to v3.0.5:

尝试将您的 Ruby on Rails 版本更新到 v3.0.5:

gem install rails --version 3.0.5

or v2.3.11:

或 v2.3.11:

gem install rails --version 2.3.11

If this isn't a new project you'll have to upgrade your application accordingly. If it was a new project, just delete the directory you created it in and create a new project again.

如果这不是一个新项目,您必须相应地升级您的应用程序。如果是新项目,只需删除您创建它的目录并重新创建一个新项目。

回答by Vishnu Atrai

update the rubygems

更新 ruby​​gems

gem update --system

宝石更新--系统