“未初始化的常数编码”使用rvm,ruby 1.9.2,bundler和乘客 [英] "uninitialized constant Encoding" using rvm, ruby 1.9.2, bundler and passenger
问题描述
我正在一个私人服务器上运行在Dreamhost上具有root权限。这里有一点关于我的环境和版本。
$`哪些ruby` -v
ruby 1.9.2p180 2011-02-18修订30909)[x86_64-linux]
$`哪个bundle` -v
Bundler版本1.0.15
$`which rails` -v
Rails 3.0 .9
除了这个错误,我的rails应用程序运行正常没有问题。但是,当我尝试使用 encode
方法更改编码字符串时:
code> NoMethodError:foobar的未定义方法encode:String
encode
应该是定义的不是这样! 如果我尝试在
: irb
中找到编码
$ irb
ruby-1.9.2-p180:001>编码
=>编码
ruby-1.9.2-p180:002> foobar.encode('utf-8')
=> foobar
但是,如果我尝试通过bundle exec使用rails控制台,未找到编码
$ bundle exec rails c staging
加载分段环境Rails 3.0.9)
ruby-1.9.2-p180:001>编码
NameError:未初始化的常量从/[REDACTED]/shared/bundle/ruby/1.8/gems/aws-s3-0.6.2/lib/aws/s3/extensions.rb:206编码
:来自(irb)的`const_missing'
:1
ruby-1.9.2-p180:002> foobar.encode('utf-8')
NoMethodError:foobar的undefined方法`encode':String
显然,安装程序没有正确加载东西,但我不知道在哪里找出来。我在这里缺少什么?
更新6/19/2011
正如Ryan Bigg所指出的,令人好奇的是,宝石的目录路径是 1.8
。但是,运行 bundle exec
表明bundler正在使用正确的ruby和rails版本:
$ bundle exec ruby
/path/to/.rvm/rubies/ruby-1.9.2-p180/bin/ruby
$ bundle exec`which ruby` -v
ruby 1.9.2p180(2011-02-18修订30909)[x86_64-linux]
$ bundle exec 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.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 @ [已删除]:/ home / [已删除] /。rvm/gems/ruby-1.9.2-p180@global
...显然没有被兑现。我的代码中没有其他地方提到 GEM_HOME
或 GEM_PATH
更新6/27/2011
Seamus问对于 .bundle / config
内容...
更新相同的想法(即 GEM_HOME
搞砸了),但更多的建议
您的 GEM_HOME
被搞砸了,可能是因为您的PATH <强>被搞砸了您可以尝试在shell中设置以下环境变量
$ export PATH = [您当前的路径但是rvm的红宝石1.9在前面]
然后运行
$ bundle install
t工作,尝试在你的shell中设置这个
$ export GEM_HOME = [你的宝石1.9宝石首页]
然后重新运行
$ bundle install
此答案的新想法:使用RVM,bundler不会安装在正确的gemset中宝石安装在不同的红宝石版本
I am at wit's end here and am turning to you all for some help on this f*#$^ encoding issue.
I am running on a private server with root permissions on Dreamhost. Here is a bit about my environment and versions.
$ `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
Aside from this error, my rails app runs fine without issue. However, when I try to change the encoding a string by using the encode
method it:
NoMethodError: undefined method `encode' for "foobar":String
encode
should be defined but it is not! Encoding
is found if I try in irb
:
$ irb
ruby-1.9.2-p180 :001 > Encoding
=> Encoding
ruby-1.9.2-p180 :002 > "foobar".encode('utf-8')
=> "foobar"
But if I try using the rails console through bundle exec, Encoding
is not found:
$ 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
Obviously the setup is not loading something correctly but I am not sure where to look to figure it out. What am I missing here?
UPDATE 6/19/2011
As Ryan Bigg pointed out, it is curious that the directory path for the gems is 1.8
. However, running bundle exec
shows that bundler is using the correct ruby and rails versions:
$ 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
Clearly something is wonky here… I just don't know what.
UPDATE 6/26/2011
Seamus asked for the $LOAD_PATH…
UPDATE 6/26/2011 (later)
Seamus asked for the Gemfile.lock and the pp ENV… In the ENV
output, I found that the GEM_PATH
was not correct. In my staging.rb
environment file, I have:
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"
…which is obviously not being honored. Nowhere else in my code is there a mention of GEM_HOME
or GEM_PATH
UPDATE 6/27/2011
Seamus asked for the .bundle/config
contents…
UPDATED same idea (that GEM_HOME
is messed up), but more suggestions
Your GEM_HOME
is messed up, possibly because your PATH is messed up. You could try setting the following environment variable in your shell
$ export PATH=[your current path but with rvm's ruby 1.9 at the front]
Then run
$ bundle install
If that doesn't work, try also setting this in your shell
$ export GEM_HOME=[your ruby 1.9 gem home]
and then re-run
$ bundle install
New ideas from this answer: Using RVM, bundler does not install in proper gemset when gems are installed in a different ruby version
这篇关于“未初始化的常数编码”使用rvm,ruby 1.9.2,bundler和乘客的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!