"uninitialized constant Encoding"使用rvm,ruby 1.9.2,bundler和passenger

con*_*are 5 encoding bundler rvm ruby-on-rails-3 ruby-1.9.2

我在这里结束了,并且正在向大家求助于这个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
Run Code Online (Sandbox Code Playgroud)

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

NoMethodError: undefined method `encode' for "foobar":String
Run Code Online (Sandbox Code Playgroud)

encode 应该定义,但它不是!Encoding如果我尝试进入,我会发现irb:

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

但是如果我尝试通过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
Run Code Online (Sandbox Code Playgroud)

显然,设置没有正确加载,但我不知道在哪里找出来.我在这里错过了什么?


更新6/19/2011

正如Ryan Bigg指出的那样,奇怪的是宝石的目录路径是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
Run Code Online (Sandbox Code Playgroud)

很显然,这里有些事情......我只是不知道是什么.


更新6/26/2011

Seamus要求$ LOAD_PATH ...


更新6/26/2011(稍后)

Seamus要求Gemfile.lockpp 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"
Run Code Online (Sandbox Code Playgroud)

......显然没有被尊重.在我的代码中没有其他地方提到GEM_HOMEGEM_PATH


更新6/27/2011

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

Sea*_*ere 0

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

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

$ export PATH=[your current path but with rvm's ruby 1.9 at the front]
Run Code Online (Sandbox Code Playgroud)

然后运行

$ bundle install
Run Code Online (Sandbox Code Playgroud)

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

$ export GEM_HOME=[your ruby 1.9 gem home]
Run Code Online (Sandbox Code Playgroud)

然后重新运行

$ bundle install
Run Code Online (Sandbox Code Playgroud)

来自这个答案的新想法:使用RVM,当gems安装在不同的ruby版本中时,bundler不会安装在正确的gem集中