【问题标题】:"uninitialized constant Etc" when running Ruby application运行 Ruby 应用程序时出现“未初始化的常量等”
【发布时间】:2011-11-03 14:33:12
【问题描述】:

我的服务器上依赖 RubyRuby On Rails 的一些应用程序似乎已经停止工作。或者至少部分如此。通过重新安装 Ruby 的不同部分,我设法让相关应用程序的 web gui 重新开始运行。但我很可能在这个过程中破坏了其他东西。

我已经设法通过一些测试对其进行了追踪,但似乎 Etc 在程序运行时以某种方式找不到。

我测试过

ruby -e 'puts Etc.getpwnam("apache").uid'

得到了

未初始化的常量等

如果我改为测试

ruby -r etc -e 'puts Etc.getpwnam("apache").uid'

我答对了

48

这是在 Amahi6 服务器上运行(运行 Fedora Core 14 64bit)。

在实际应用中失败的代码示例是

#!/usr/bin/env ruby
# Amahi Home Server
# Copyright (C) 2007-2010 Amahi
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License v3
# (29 June 2007), as published in the COPYING file.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# file COPYING for more details.
#
# You should have received a copy of the GNU General Public
# License along with this program; if not, write to the Amahi
# team at http://www.amahi.org/ under "Contact Us."

require File.dirname(__FILE__) + '/../config/boot'
#require 'commands/runner'
require 'optparse'

# switch to apache:users first
uid = Etc.getpwnam("apache").uid
gid = Etc.getgrnam("users").gid
Process.gid = gid
Process.egid = gid
Process.uid = uid
Process.euid = uid
...

同样失败

未初始化的常量等

澄清:我根本没有更改此代码,它之前一直在当前状态下工作

我搞砸了什么? :)

更新: 现在安装的 Ruby 版本是 1.8.7

更新 2:

如果我尝试为 rubygemsetc 手动添加 require 会失败,但会抱怨另一个包。所以我认为我的红宝石核心从根本上搞砸了。

/usr/lib64/ruby/gems/1.8/gems/activesupport-2.3.4/lib/active_support/dependencies.rb:55: 未初始化的常量 ActiveSupport::Dependencies::Mutex (NameError) 从 /usr/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:36:in gem_original_require' from /usr/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:36:inrequire' 从 /usr/lib64/ruby/gems/1.8/gems/activesupport-2.3.4/lib/active_support.rb:56 从 /usr/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:36:in gem_original_require' from /usr/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:36:inrequire' 从 /usr/lib64/ruby/gems/1.8/gems/activerecord-2.3.4/lib/active_record.rb:25 从 /usr/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:36:in gem_original_require' from /usr/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:36:inrequire' 来自 /var/hda/platform/html/script/install-app:70

【问题讨论】:

  • “重新安装 Ruby 的不同部分”到底是什么意思?如果您也可以使用 ruby​​ 版本(ruby -v),这将有所帮助。
  • 那是很久以前的事了,恐怕有点模糊。但我想我使用 yum 重新安装了 ruby​​ 和 libs。所以 yum reinstall ruby​​yum reinstall ruby​​-libs。也许有宝石的东西,但我不这么认为。
  • 您可以尝试使用“rake gems:install”(在 rails 应用所在的目录中)重新安装所需的 gem。恐怕最好的办法是重新安装 Amahi,因为安装脚本看起来很复杂。
  • 那太糟糕了:)...我安装了很多东西...呵呵...当尝试运行 rake 命令时,我也收到一个错误:未初始化的常量 ActiveSupport::依赖::互斥
  • stackoverflow.com/questions/5176782/…,它应该可以让你继续前进。

标签: ruby-on-rails ruby rubygems fedora


【解决方案1】:

记住'rubygems',

命令行:

ruby -rubygems -e 'puts Etc.getpwnam("apache").uid'

脚本:

require 'rubygems'
puts Etc.getpwnam("apache").uid

【讨论】:

    【解决方案2】:

    您似乎缺少require 'rubygems'require 'etc'(将它们放在require 'optparse' 下方)

    【讨论】:

    • 但我根本没有更改 Amahi ruby​​ 代码。它刚刚停止工作。很奇怪,我突然必须通过代码并添加以前不需要的 require 语句?不是说可能有一个 conf 文件告诉 ruby​​ 总是包含我可能已经删除或覆盖的这些内容吗?
    • 恐怕在那个问题上我帮不了你。我不知道 Amahi 是如何工作的。事实上,在回答你的问题之前,我什至不知道它存在 :-)
    【解决方案3】:

    最后是 rails 和 gems 的版本是新的。已降级为 gems 1.3.7rails 2.3.8

    gem update --system 1.3.7
    
    gem uninstall rails
    
    gem install rails --version 2.3.8
    

    【讨论】:

      猜你喜欢
      • 2015-11-07
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-10-10
      • 1970-01-01
      • 2011-10-13
      • 1970-01-01
      相关资源
      最近更新 更多