“uninitialized constant Encoding” using rvm, ruby 1.9.2, bundler and passenger

蓝咒 提交于 2019-12-23 11:45:04

问题


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…


回答1:


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



来源:https://stackoverflow.com/questions/6400581/uninitialized-constant-encoding-using-rvm-ruby-1-9-2-bundler-and-passenger

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!