5

我在这里束手无策,正在向大家寻求有关此 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 应该定义但不是!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

显然,设置没有正确加载某些内容,但我不确定在哪里可以找到它。我在这里想念什么?


2011 年 6 月 19 日更新

正如 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

很明显这里有些不正常……我只是不知道是什么。


2011 年 6 月 26 日更新

Seamus 要求$LOAD_PATH ......


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

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


2011 年 6 月 27 日更新

西莫索要.bundle/config内容……

4

1 回答 1

0

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

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

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

于 2011-06-27T14:13:54.350 回答