2010-08-18 29 views
5

我刚刚开始从Ruby 1.8.7升级到Ruby 1.9.2(使用RVM)的升级过程。我的所有应用程序都使用'script/server'(或'rails server')运行于1.9.2,但是,只有Rails 3.0.0 RC应用程序可与Passenger配合使用。通过Rails的2.3.8应用程序提供的错误消息是:在US-ASCIIRVM,Ruby 1.9.2,Rails 2.3.8,Passenger和“US-ASCII中的无效字节序列”

我猜,这是一个问题,乘客

无效字节序列。我使用RVM指南安装了Passenger 2.2.15,发现here。任何想法如何解决这个错误?谢谢。我已更新以包含堆栈跟踪:

/Users/kevin/.rvm/gems/ruby-1.9.2-p0/gems/actionpack-2.3.8/lib/action_view/template_handlers/erb.rb:14:in `compile' 
/Users/kevin/.rvm/gems/ruby-1.9.2-p0/gems/actionpack-2.3.8/lib/action_view/template_handler.rb:11:in `call' 
/Users/kevin/.rvm/gems/ruby-1.9.2-p0/gems/actionpack-2.3.8/lib/action_view/renderable.rb:19:in `compiled_source' 
/Users/kevin/.rvm/gems/ruby-1.9.2-p0/gems/actionpack-2.3.8/lib/action_view/renderable.rb:68:in `compile!' 
/Users/kevin/.rvm/gems/ruby-1.9.2-p0/gems/actionpack-2.3.8/lib/action_view/renderable.rb:61:in `compile' 
/Users/kevin/.rvm/gems/ruby-1.9.2-p0/gems/actionpack-2.3.8/lib/action_view/renderable.rb:28:in `render' 
/Users/kevin/.rvm/gems/ruby-1.9.2-p0/gems/actionpack-2.3.8/lib/action_view/template.rb:205:in `render_template' 
/Users/kevin/.rvm/gems/ruby-1.9.2-p0/gems/actionpack-2.3.8/lib/action_view/base.rb:265:in `render' 
/Users/kevin/.rvm/gems/ruby-1.9.2-p0/gems/actionpack-2.3.8/lib/action_view/base.rb:352:in `_render_with_layout' 
/Users/kevin/.rvm/gems/ruby-1.9.2-p0/gems/actionpack-2.3.8/lib/action_view/base.rb:262:in `render' 
/Users/kevin/.rvm/gems/ruby-1.9.2-p0/gems/actionpack-2.3.8/lib/action_controller/base.rb:1250:in `render_for_file' 
/Users/kevin/.rvm/gems/ruby-1.9.2-p0/gems/actionpack-2.3.8/lib/action_controller/base.rb:942:in `render' 
/Users/kevin/.rvm/gems/ruby-1.9.2-p0/gems/actionpack-2.3.8/lib/action_controller/benchmarking.rb:51:in `block in render_with_benchmark' 
/Users/kevin/.rvm/gems/ruby-1.9.2-p0/gems/activesupport-2.3.8/lib/active_support/core_ext/benchmark.rb:17:in `block in ms' 
/Users/kevin/.rvm/rubies/ruby-1.9.2-p0/lib/ruby/1.9.1/benchmark.rb:309:in `realtime' 
/Users/kevin/.rvm/gems/ruby-1.9.2-p0/gems/activesupport-2.3.8/lib/active_support/core_ext/benchmark.rb:17:in `ms' 
/Users/kevin/.rvm/gems/ruby-1.9.2-p0/gems/actionpack-2.3.8/lib/action_controller/benchmarking.rb:51:in `render_with_benchmark' 
/Users/kevin/.rvm/gems/ruby-1.9.2-p0/gems/actionpack-2.3.8/lib/action_controller/mime_responds.rb:135:in `block in custom' 
/Users/kevin/.rvm/gems/ruby-1.9.2-p0/gems/actionpack-2.3.8/lib/action_controller/mime_responds.rb:179:in `call' 
/Users/kevin/.rvm/gems/ruby-1.9.2-p0/gems/actionpack-2.3.8/lib/action_controller/mime_responds.rb:179:in `block in respond' 
/Users/kevin/.rvm/gems/ruby-1.9.2-p0/gems/actionpack-2.3.8/lib/action_controller/mime_responds.rb:173:in `each' 
/Users/kevin/.rvm/gems/ruby-1.9.2-p0/gems/actionpack-2.3.8/lib/action_controller/mime_responds.rb:173:in `respond' 
/Users/kevin/.rvm/gems/ruby-1.9.2-p0/gems/actionpack-2.3.8/lib/action_controller/mime_responds.rb:107:in `respond_to' 
/Users/kevin/Sites/sample/app/controllers/main_controller.rb:7:in `index' 
+0

有关错误的其他信息?它发生在哪里?堆栈跟踪也许? – 2010-08-18 20:14:11

+0

刚刚更新以包含它。 – 2010-08-18 20:18:38

回答

6

尝试在main_controller.rb文件的顶部添加

# encoding: UTF-8
。如果这有效,你在处理源文件中的非美国ASCII字符。

在Ruby 1.9,我们正在处理的三种编码上下文:

  • 源代码编码:字符串在源文件中解释为默认的US-ASCII,除非魔评论我上面所列内容存在。
  • 外部编码:假设文本文件中的字符与环境编码相同。但是可以指定要使用的编码。例如:open(mydata.txt,“r:UTF-8”)。
  • 内部编码:指定从文件中读取文本数据的方式。默认情况下,这是零,这意味着它将与用于读取它的编码相同。如果需要不同的东西,可以在IO.open中指定。如:开(mydata.txt, 'R:UTF-8:UTF-16LE')

欲了解更多信息,我会阅读编码James Edward Gray II's great articles

+1

谢谢,但我在源文件中没有任何非US ASCII字符。我认为这肯定是一个乘客问题(因为这些项目在杂种下运行得很好)。 – 2010-08-19 15:24:41

1

欢迎来到强制字符串编码的美妙世界;错误是Ruby 1.9.x与Ruby 1.8.x在字符串中的行为差异。

检查http://blog.phusion.nl/2009/02/02/getting-ready-for-ruby-191/ - 可能有帮助。你可能只需要更新你的gemset。

+0

那么这是乘客宝石的问题吗?使用内置的Mongreal(脚本/服务器),应用程序似乎运行良好。也似乎没有解释为什么3.0.0 RC应用程序正在工作。有任何想法吗? – 2010-08-18 20:58:13

2

我同意pjmorse有关环境变量的原因,特别是在我的Passenger/Rails设置中,罪魁祸首是LANG值。

当通过脚本/服务器启动我的Rails应用程序时,我有LANG = en_CA.UTF-8,但在使用Passenger提升应用程序时没有。

解决方案: 修改乘客配置与包装开始红宝石,看到http://blog.phusion.nl/2008/12/16/passing-environment-variables-to-ruby-from-phusion-passenger/

以此作为包装:

#!/bin/sh 
export LANG=en_CA.UTF-8 
exec "/Your_Default_Ruby_Path/ruby" "[email protected]" 

注Your_Default_Ruby_Path是无论是在HTTP的PassengerRuby值。在设置包装之前进行配置。

5

我在Ubuntu上有类似的问题(11。10),因为这是我的/ etc/apache2的/ envvars中:

## The locale used by some modules like mod_dav 
export LANG=C 
## Uncomment the following line to use the system default locale instead: 
#. /etc/default/locale 

交换意见出来这样一来使用/ etc /默认/区域设置(其中包含LANG="en_US.UTF-8")解决了我的问题,而不必为我的红宝石做一个包装。

+0

这个答案适用于我在Ubuntu 12.04上运行的ruby 1.9.3中的rails 3.2应用程序。在应用程序中使用的某些宝石的gemspec中有UTF-8编码的字符。 – 2012-11-30 17:10:01

+1

现货!谢谢你,节省了很多痛苦。 – 2012-12-21 10:32:33

相关问题