我刚刚开始从 Ruby 1.8.7 升级到 Ruby 1.9.2(使用 RVM)。我的所有应用程序都使用“脚本/服务器”(或“rails 服务器”)和 1.9.2 运行,但是,只有 Rails 3.0.0 RC 应用程序可以与 Passenger 一起使用。 Rails 2.3.8 应用给出的错误信息是:
invalid byte sequence in US-ASCII
我猜这是一个 Passenger 问题。我使用找到的 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'
最佳答案
尝试添加
# encoding: UTF-8在 main_controller.rb 文件的顶部。如果可行,则说明您正在处理源文件中的非美国 ASCII 字符。
在 Ruby 1.9 中,我们处理三种编码上下文:
- 源代码编码:默认情况下,源文件中的字符串被解释为 US-ASCII,除非存在我上面列出的魔术注释。
- 外部编码:假定文本文件中的字符采用与环境相同的编码。但是可以指定要使用的编码。例如:打开(mydata.txt,“r:UTF-8”)。
- 内部编码:指定文本数据从文件中读取后的编码方式。默认情况下这是 nil,这意味着它将与用于读取它的编码相同。如果需要不同的东西,可以在 IO.open 中指定。例如:open(mydata.txt, 'r:UTF-8:UTF-16LE')
有关更多信息,我阅读了 James Edward Gray II's great articles关于编码。
关于ruby-on-rails - RVM、Ruby 1.9.2、Rails 2.3.8、Passenger 和 "invalid byte sequence in US-ASCII",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3515810/