title: invalid byte sequence utf-8 error in rails 2.3 and ruby 1.9
body: <p>I've migrated my app from Rails 2.3.8 / Ruby 1.8.7 to 2.3.14 / Ruby 1.9.2 - it hasn't been easy, but basically works. An issue I keep having is that in the occasional Haml template I'll get the following error:</p>
  
  <pre><code>ActionView::TemplateError (invalid byte sequence in UTF-8) on line #....
  </code></pre>
  
  <p>This is an encoding issue, and I've seen some suggestions on how to deal with it (using <code>Iconv.conv</code>), but the things I tried didn't seem to work. How do I resolve this on the application level (not having to patch every template)? Thanks.</p>
  
  <p><strong>EDIT:</strong> Some stack trace</p>
  
  <pre><code>ActionView::TemplateError (invalid byte sequence in UTF-8) on line #28 of app/views/users/_user.haml:
  27:     - if user.valid?
  28:       - image_onclick = remote_function( :url =&gt; { :action =&gt; :toggle_image, :id =&gt; user.id } )
  
      vendor/rails/activesupport/lib/active_support/core_ext/object/blank.rb:68:in `=~'
      vendor/rails/activesupport/lib/active_support/core_ext/object/blank.rb:68:in `!~'
      vendor/rails/activesupport/lib/active_support/core_ext/object/blank.rb:68:in `blank?'
      vendor/rails/activerecord/lib/active_record/validations.rb:478:in `block (2 levels) in validates_each'
      vendor/rails/activerecord/lib/active_record/validations.rb:476:in `each'
      vendor/rails/activerecord/lib/active_record/validations.rb:476:in `block in validates_each'
      ... etc
  </code></pre>
  
  <p>The database tables' <code>CHARSET</code> is encoded in <code>UTF-8</code>. I didn't assign any specific encoding to my templates, although I set</p>
  
  <pre><code>Encoding.default_internal = 'utf-8'
  Encoding.default_external = 'utf-8'
  </code></pre>
  
  <p>in <code>environment.rb</code></p>