[英]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-8at the top of your main_controller.rb file.
In Ruby 1.9, we're dealing with three encoding contexts: 在Ruby 1.9中,我们处理三种编码上下文:
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.