views:

706

answers:

3

I just started the upgrade process from Ruby 1.8.7 to Ruby 1.9.2 (using 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. The error message given by Rails 2.3.8 applications is:

invalid byte sequence in US-ASCII

I'm guessing that this is a Passenger issue. I installed Passenger 2.2.15 using the RVM guide found here. 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'
+1  A: 

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.

Check http://blog.phusion.nl/2009/02/02/getting-ready-for-ruby-191/ -- might be helpful. You probably just need to update your gemset.

todb
Is this a problem with the passenger gem then? The applications appear to run fine using the built in Mongreal (script/server). Also it doesn't seem to explain why 3.0.0 RC applications are working. Any ideas?
Kevin Sylvestre
+1  A: 

Try adding

# encoding: UTF-8
at the top of your main_controller.rb file. If that works, you're dealing with a non US ASCII character in your source file.

In Ruby 1.9, we're dealing with three encoding contexts:

  • Source code encoding: Strings in a source file are interpreted as US-ASCII by default, unless the magic comment I list above is present.
  • 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").
  • 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. If something different is needed, it can be specified in IO.open. Eg: open(mydata.txt, 'r:UTF-8:UTF-16LE')

For more info, I'd read James Edward Gray II's great articles on encoding.

Alkaline
Thanks, but I don't have any non US ASCII characters in the source files. I think it must be a passenger issue (given that the projects all run fine under mongrel).
Kevin Sylvestre
+1  A: 

I had a similar issue with a different server, and environment variables turned out to be the culprit.

pjmorse