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

5 に答える 5

6

追加してみる

# エンコーディング: UTF-8
main_controller.rb ファイルの上部にあります。それが機能する場合は、ソース ファイルで非 US ASCII 文字を扱っています。

Ruby 1.9 では、3 つのエンコーディング コンテキストを扱っています。

  • ソース コードのエンコーディング: ソース ファイル内の文字列は、上記のマジック コメントが存在しない限り、デフォルトで US-ASCII として解釈されます。
  • 外部エンコーディング: テキスト ファイル内の文字は、環境と同じエンコーディングであると見なされます。ただし、使用するエンコーディングを指定できます。例: open(mydata.txt, "r:UTF-8")。
  • 内部エンコード: ファイルから読み取られたテキスト データのエンコード方法を指定します。デフォルトでは、これは nil です。つまり、読み取りに使用されるエンコーディングと同じになります。別のものが必要な場合は、IO.open で指定できます。例: open(mydata.txt, 'r:UTF-8:UTF-16LE')

詳細については、James Edward Gray II のエンコーディングに関する素晴らしい記事を読んでください。

于 2010-08-19T00:41:11.170 に答える
5

これは /etc/apache2/envvars にあったため、Ubuntu (11.10) でも同様の問題が発生しました。

## 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") を使用すると、ルビーのラッパーを作成しなくても問題が解決しました。

于 2012-03-03T18:56:44.237 に答える
3

別のサーバーで同様の問題が発生し、環境変数が原因であることが判明しました

于 2010-09-08T15:57:14.740 に答える
2

私は、環境変数の原因に関する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値に含まれていたものです。

于 2010-12-01T20:08:57.720 に答える
1

強制文字列エンコーディングのすばらしい世界へようこそ。エラーは、文字列における Ruby 1.9.x と Ruby 1.8.x の動作の違いです。

http://blog.phusion.nl/2009/02/02/getting-ready-for-ruby-191/を確認してください-- 参考になるかもしれません。おそらく、gemset を更新する必要があるだけです。

于 2010-08-18T20:33:31.630 に答える