简体   繁体   English

RVM,Ruby 1.9.2,Rails 2.3.8,Passenger和“US-ASCII中的无效字节序列”

[英]RVM, Ruby 1.9.2, Rails 2.3.8, Passenger and “invalid byte sequence in US-ASCII”

I just started the upgrade process from Ruby 1.8.7 to Ruby 1.9.2 (using RVM). 我刚刚开始从Ruby 1.8.7升级到Ruby 1.9.2(使用RVM)。 I have all my applications running using 'script/server' (or 'rails server') with 1.9.2, however, only Rails 3.0.0 RC applications work with Passenger. 我的所有应用程序都使用“脚本/服务器”(或“rails服务器”)和1.9.2运行,但只有Rails 3.0.0 RC应用程序可以与Passenger一起使用。 The error message given by Rails 2.3.8 applications is: Rails 2.3.8应用程序给出的错误消息是:

invalid byte sequence in US-ASCII US-ASCII中的无效字节序列

I'm guessing that this is a Passenger issue. 我猜这是一个乘客问题。 I installed Passenger 2.2.15 using the RVM guide found here . 我使用此处的RVM指南安装了Passenger 2.2.15。 Any ideas how to fix this bug? 任何想法如何解决这个错误? Thanks. 谢谢。 I've updated to include a stack trace: 我已更新为包含堆栈跟踪:

/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'

Try adding 尝试添加

# encoding: UTF-8
at the top of your main_controller.rb file. 在main_controller.rb文件的顶部。 If that works, you're dealing with a non US ASCII character in your source file. 如果可行,则在源文件中处理非US ASCII字符。

In Ruby 1.9, we're dealing with three encoding contexts: 在Ruby 1.9中,我们处理三种编码上下文:

  • Source code encoding: Strings in a source file are interpreted as US-ASCII by default, unless the magic comment I list above is present. 源代码编码:默认情况下,源文件中的字符串被解释为US-ASCII,除非上面列出的魔术注释存在。
  • External encoding: The characters in a text file are assumed to be in the same encoding as the environment. 外部编码:假定文本文件中的字符与环境的编码相同。 However one can specify the encoding to use. 但是,可以指定要使用的编码。 Eg: open(mydata.txt, "r:UTF-8"). 例如:打开(mydata.txt,“r:UTF-8”)。
  • Internal encoding: That specifies how the text data is encoded once read from a file. 内部编码:指定从文件读取后文本数据的编码方式。 By default this is nil, meaning it will be the same as the encoding used to read it. 默认情况下,这是nil,这意味着它将与用于读取它的编码相同。 If something different is needed, it can be specified in IO.open. 如果需要不同的东西,可以在IO.open中指定。 Eg: open(mydata.txt, 'r:UTF-8:UTF-16LE') 例如:open(mydata.txt,'r:UTF-8:UTF-16LE')

For more info, I'd read James Edward Gray II's great articles on encoding. 有关更多信息,我会阅读James Edward Gray II关于编码的精彩文章

I had similar issues on Ubuntu (11.10) because this was in my /etc/apache2/envvars: 我在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

Swapping the comments out on this one to use the /etc/default/locale (which contains LANG="en_US.UTF-8" ) resolved the issue for me without having to make a wrapper for my ruby. 将注释交换到这一个以使用/ etc / default / locale(包含LANG="en_US.UTF-8" )解决了我的问题,而无需为我的ruby创建一个包装器。

我在使用不同的服务器时遇到了类似的问题, 环境变量也是罪魁祸首

I agree with pjmorse regarding the environment variable cause, specially in my Passenger/Rails set-up, the culprit was the LANG value. 我同意pjmorse关于环境变量的原因,特别是在我的Passenger / Rails设置中,罪魁祸首是LANG值。

When starting my Rails app through script/server, I had LANG=en_CA.UTF-8, but not when raising the app with Passenger. 当我通过脚本/服务器启动我的Rails应用程序时,我有LANG = en_CA.UTF-8,但在使用Passenger提升应用程序时却没有。

Solution: Modify the Passenger configuration to start Ruby with a wrapper, see http://blog.phusion.nl/2008/12/16/passing-environment-variables-to-ruby-from-phusion-passenger/ 解决方案:修改Passenger配置以使用包装器启动Ruby,请参阅http://blog.phusion.nl/2008/12/16/passing-environment-variables-to-ruby-from-phusion-passenger/

Use this as a wrapper: 使用它作为包装器:

#!/bin/sh
export LANG=en_CA.UTF-8
exec "/Your_Default_Ruby_Path/ruby" "$@"

Note Your_Default_Ruby_Path is whatever was in the PassengerRuby value of the http.conf before you set-up the wrapper. 注意在设置包装器之前,Your_Default_Ruby_Path是http.conf的PassengerRuby值中的任何值。

Welcome to the wonderful world of forced string encoding; 欢迎来到强制字符串编码的精彩世界; the error is a Ruby 1.9.x vs Ruby 1.8.x behavior difference in strings. 错误是Ruby 1.9.x vs Ruby 1.8.x字符串中的行为差异。

Check http://blog.phusion.nl/2009/02/02/getting-ready-for-ruby-191/ -- might be helpful. 查看http://blog.phusion.nl/2009/02/02/getting-ready-for-ruby-191/ - 可能会有所帮助。 You probably just need to update your gemset. 您可能只需要更新您的gemset。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 US-ASCII中的无效字节序列(Ruby 1.9 + rails 2.3.8 + mongodb + mongo_mapper) - invalid byte sequence in US-ASCII (Ruby 1.9 + rails 2.3.8 + mongodb + mongo_mapper) 将Ruby升级到1.9.2后,Rails查看错误“US-ASCII中的无效字节序列”错误 - Rails view error “invalid byte sequence in US-ASCII” error after upgrading Ruby to 1.9.2 ArgumentError(US-ASCII中无效的字节序列):在ruby升级1.9.3中 - ArgumentError (invalid byte sequence in US-ASCII): in ruby upgrade 1.9.3 在US-ASCII问题中使用ruby 1.9.3的Rails 3.2无效字节序列 - Rails 3.2 with ruby 1.9.3 invalid byte sequence in US-ASCII issue Rails + Ruby 1.9“ US-ASCII中无效的字节序” - Rails + Ruby 1.9 “invalid byte squence in US-ASCII” US-ASCII whith数组中的无效字节序列 - invalid byte sequence in US-ASCII whith array MembersController中的ArgumentError#登录US-ASCII中的无效字节序列 - ArgumentError in MembersController#login invalid byte sequence in US-ASCII US-ASCII(ArgumentError)中的字节序列无效,没有任何帮助 - invalid byte sequence in US-ASCII (ArgumentError), nothing helps Rails:运行 rake db:seed 时 US-ASCII 中的字节序列无效(参数错误) - Rails: Invalid byte sequence in US-ASCII (Argument Error) when I run rake db:seed rake任务因US-ASCII中的无效字节序列而失败 - rake tasks fail with invalid byte sequence in US-ASCII
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM