使用rvm、ruby 1.9.2、bundler和passenger的“未初始化常量编码”

2024-02-07

我在这里无计可施,正在向大家寻求有关 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 应该 http://ruby-doc.org/core/classes/String.html#M001113已定义但事实并非如此!Encoding如果我尝试的话会发现irb:

$ 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

显然,安装程序没有正确加载某些内容,但我不知道在哪里可以找到它。我在这里缺少什么?


更新 6/19/2011

正如 Ryan Bigg 指出的那样,奇怪的是 gems 的目录路径是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

显然这里有些东西很奇怪……我只是不知道是什么。


更新 6/26/2011

西莫要求$LOAD_PATH https://gist.github.com/1047295


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

西莫要求Gemfile.lock https://gist.github.com/1048157pp ENV https://gist.github.com/1048155… 在里面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 or GEM_PATH


更新 6/27/2011

西莫要求.bundle/config https://gist.github.com/1049412内容…


UPDATED同样的想法(即GEM_HOME搞砸了),但还有更多建议

Your GEM_HOME很混乱,可能是因为你的路径搞砸了。您可以尝试设置以下环境变量在你的壳里

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

Then run

$ bundle install

如果这不起作用,请尝试在您的 shell 中进行设置

$ export GEM_HOME=[your ruby 1.9 gem home]

然后重新运行

$ bundle install

这个答案的新想法:使用 RVM,当 gem 安装在不同的 ruby​​ 版本中时,bundler 不会安装在正确的 gemset 中 https://stackoverflow.com/questions/4414936/using-rvm-bundler-does-not-install-in-proper-gemset-when-gems-are-installed-in-a

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

使用rvm、ruby 1.9.2、bundler和passenger的“未初始化常量编码” 的相关文章

随机推荐