【问题标题】:"uninitialized constant Encoding" using rvm, ruby 1.9.2, bundler and passenger使用 rvm、ruby 1.9.2、捆绑器和乘客的“未初始化常量编码”
【发布时间】:2011-09-18 00:56:11
【问题描述】:

我对此束手无策,正在向大家寻求有关此 f*#$^ 编码问题的帮助。

我在 Dreamhost 上具有 root 权限的私人服务器上运行。这是我的环境和版本。

$ `which ruby` -v
ruby 1.9.2p180 (2011-02-18 revision 30909) [x86_64-linux]
$ `which bundle` -v
Bundler version 1.0.15
$ `which rails` -v
Rails 3.0.9

除了这个错误之外,我的 rails 应用程序运行良好,没有问题。但是,当我尝试使用 encode 方法更改字符串的编码时:

NoMethodError: undefined method `encode' for "foobar":String

encode should be 已定义但不是!如果我尝试在irb 中找到Encoding:

$ irb
ruby-1.9.2-p180 :001 > Encoding
 => Encoding
ruby-1.9.2-p180 :002 > "foobar".encode('utf-8')
 => "foobar"

但如果我尝试通过 bundle exec 使用 rails 控制台,则找不到Encoding:

$ bundle exec rails c staging
Loading staging environment (Rails 3.0.9)
ruby-1.9.2-p180 :001 > Encoding
NameError: uninitialized constant Encoding
    from /[REDACTED]/shared/bundle/ruby/1.8/gems/aws-s3-0.6.2/lib/aws/s3/extensions.rb:206:in `const_missing'
    from (irb):1
ruby-1.9.2-p180 :002 > "foobar".encode('utf-8')
    NoMethodError: undefined method `encode' for "foobar":String

显然,设置没有正确加载某些内容,但我不确定在哪里可以找到它。我在这里想念什么?


2011 年 6 月 19 日更新

正如 Ryan Bigg 所指出的,奇怪的是 gem 的目录路径是 1.8。但是,运行 bundle exec 表明 bundler 使用了正确的 ruby​​ 和 rails 版本:

$ bundle exec which ruby
/path/to/.rvm/rubies/ruby-1.9.2-p180/bin/ruby
$ bundle exec `which ruby` -v
ruby 1.9.2p180 (2011-02-18 revision 30909) [x86_64-linux]
$ bundle exec which rails
/path/to/shared/bundle/ruby/1.8/bin/rails
$ bundle exec `which rails` -v
Rails 3.0.9

很明显这里有些不正常……我只是不知道是什么。


2011 年 6 月 26 日更新

Seamus 要求$LOAD_PATH...


2011 年 6 月 26 日更新(稍后)

Seamus 要求Gemfile.lock 和pp ENV... 在ENV 输出中,我发现GEM_PATH 不正确。在我的staging.rb 环境文件中,我有:

GEM_HOME = "/home/[REDACTED]/.rvm/gems/ruby-1.9.2-p180@[REDACTED]"
GEM_PATH = "/home/[REDACTED]/.rvm/gems/ruby-1.9.2-p180@[REDACTED]:/home/[REDACTED]/.rvm/gems/ruby-1.9.2-p180@global"

……这显然不被尊重。我的代码中没有其他地方提到 GEM_HOME 或 GEM_PATH


2011 年 6 月 27 日更新

Seamus 要求提供.bundle/config 的内容……

【问题讨论】:

  • 您的 /shared/bundle/ruby/1.8/ 泄露了它:您的控制台仍在使用 1.8,而不是 1.9。
  • 但是提示说“ruby-1.9.2-p180”?
  • @coneybeare:但是/shared/bundle/ruby/1.8 说的是1.8?如果您不使用它,请删除 /shared/bundle/ruby/1.8。您可能需要再次运行bundle install。
  • 我确实尝试删除它并重做 bundle install --deployment (与 cap deploy 使用的同一行)......它在 ruby​​/1.8 下创建了 gems 尽管加载了 1.9 gems(如上图所示使用捆绑执行)。用于安装的行上限是:“bundle install --gemfile /path/to/releases/20110619032757/Gemfile --path /path/to/shared/bundle --deployment --quiet --without development test”
  • 当你在控制台时,$LOAD_PATH 是什么?

标签: ruby-on-rails-3 encoding rvm bundler ruby-1.9.2


【解决方案1】:

更新相同的想法(GEM_HOME 搞砸了),但更多建议

你的GEM_HOME 搞砸了,可能是因为你的 PATH 搞砸了。您可以尝试在您的 shell 中设置以下环境变量

$ export PATH=[your current path but with rvm's ruby 1.9 at the front]

然后运行

$ bundle install

如果这不起作用,请尝试在你的 shell 中设置它

$ export GEM_HOME=[your ruby 1.9 gem home]

然后重新运行

$ bundle install

来自这个答案的新想法:Using RVM, bundler does not install in proper gemset when gems are installed in a different ruby version

【讨论】:

  • 它没有帮助。我删除了我的 shared/bundle 文件夹,然后重新运行了 bundle install 命令。它仍然将其设置为 1.8。我认为 gem 路径只有 1.8 作为名称,而不是内容。在文件夹中,所有的 gem 都很好,并且是最新的。
  • 要清楚,我检查的方法是按照指示编辑 boot.rb 文件,删除共享包目录,重新安装包,然后检查 rails c 是否存在编码。跨度>
  • 您是否完全卸载并重新安装了 bundler gem?你的 .bundle/config 文件的内容是什么(如果有的话)?
  • 我刚刚卸载并重新安装了 gem。我用 bundle/config 文件更新了这个问题。尽管如此,它还是安装在 1.8 目录下。根据控制台提示和 bundle exec ruby​​ 版本,它似乎仍在使用 1.9.2。
  • 尝试删除 .bundle/config 和 Gemfile.lock 并重新运行包更新。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2011-12-09
  • 1970-01-01
  • 2011-07-20
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多