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

时间:2011-06-19 04:36:50

标签: ruby-on-rails-3 encoding rvm bundler 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

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

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

encode should be已定义,但事实并非如此!如果我尝试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指出的那样,奇怪的是宝石的目录路径是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

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"

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


更新6/27/2011

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

1 个答案:

答案 0 :(得分:0)

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

你的GEM_HOME搞砸了,可能因为你的路径搞砸了。您可以尝试在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