[英]invalid byte sequence in US-ASCII (Ruby 1.9 + rails 2.3.8 + mongodb + mongo_mapper)
[英]RVM, Ruby 1.9.2, Rails 2.3.8, Passenger and “invalid byte sequence in US-ASCII”
我剛剛開始從Ruby 1.8.7升級到Ruby 1.9.2(使用RVM)。 我的所有應用程序都使用“腳本/服務器”(或“rails服務器”)和1.9.2運行,但只有Rails 3.0.0 RC應用程序可以與Passenger一起使用。 Rails 2.3.8應用程序給出的錯誤消息是:
US-ASCII中的無效字節序列
我猜這是一個乘客問題。 我使用此處的RVM指南安裝了Passenger 2.2.15。 任何想法如何解決這個錯誤? 謝謝。 我已更新為包含堆棧跟蹤:
/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文件的頂部。 如果可行,則在源文件中處理非US ASCII字符。
在Ruby 1.9中,我們處理三種編碼上下文:
有關更多信息,我會閱讀James Edward Gray II關於編碼的精彩文章 。
我在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 / default / locale(包含LANG="en_US.UTF-8"
)解決了我的問題,而無需為我的ruby創建一個包裝器。
我在使用不同的服務器時遇到了類似的問題, 環境變量也是罪魁禍首 。
我同意pjmorse關於環境變量的原因,特別是在我的Passenger / Rails設置中,罪魁禍首是LANG值。
當我通過腳本/服務器啟動我的Rails應用程序時,我有LANG = en_CA.UTF-8,但在使用Passenger提升應用程序時卻沒有。
解決方案:修改Passenger配置以使用包裝器啟動Ruby,請參閱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" "$@"
注意在設置包裝器之前,Your_Default_Ruby_Path是http.conf的PassengerRuby值中的任何值。
歡迎來到強制字符串編碼的精彩世界; 錯誤是Ruby 1.9.x vs Ruby 1.8.x字符串中的行為差異。
查看http://blog.phusion.nl/2009/02/02/getting-ready-for-ruby-191/ - 可能會有所幫助。 您可能只需要更新您的gemset。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.