title: Rails + Ruby 1.9 "invalid byte squence in US-ASCII"
body: <p>After upgrading to ruby 1.9 we began to notice pages failing to render from the rails template renderer when a user used a non-ASCII character. Specifically "é". I was able to resolve this issue on one of our staging servers, but I have not been able to reproduce the fix on our production server.</p>
  
  <p>The fix that seemed to work the first time:</p>
  
  <ol>
  <li><p>Converted the database from latin1 to utf8 using the convert_charset tool available here: <a href="http://www.mysqlperformanceblog.com/2009/03/17/converting-character-sets/" rel="nofollow noreferrer">http://www.mysqlperformanceblog.com/2009/03/17/converting-character-sets/</a>. (including setting <code>default_character_set=utf8</code> in my.cnf and running <code>SET GLOBAL character_set_server=utf8</code></p></li>
  <li><p>Switched to the sam-mysql-ruby adapter (instead of the standard mysql adapter: <a href="http://gemcutter.org/gems/sam-mysql-ruby" rel="nofollow noreferrer">http://gemcutter.org/gems/sam-mysql-ruby</a>) </p></li>
  <li><p>Restarted rails</p></li>
  </ol>
  
  <p>The error is:
  <code>"invalid byte sequence in US-ASCII"</code>
  Oddly, after following the steps above the error has not changed on our production server. Setting <code>encoding: utf8</code> in database.yml does not change the error either.</p>
  
  <p>The error raised on the following line of code:
  <code>&lt;%= link_to h(question.title), question_path(question) %&gt;</code></p>
  
  <p>This blog seems to suggest a fix, but it mentions that this should not be a problem in 1.9: <a href="http://www.igvita.com/2007/04/11/secure-utf-8-input-in-rails/" rel="nofollow noreferrer">http://www.igvita.com/2007/04/11/secure-utf-8-input-in-rails/</a> (and it's over 2 years old).</p>
  
  <p>I imagine this problem might soon affect a lot of people as more rails developers people switch to 1.9.</p>