title: How do I replace accented Latin characters in Ruby?
body: <p>I have an <code>ActiveRecord</code> model, <code>Foo</code>, which has a <code>name</code> field.  I'd like users to be able to search by name, but I'd like the search to ignore case and any accents.  Thus, I'm also storing a <code>canonical_name</code> field against which to search:</p>
  
  <pre><code>class Foo
    validates_presence_of :name
  
    before_validate :set_canonical_name
  
    private
  
    def set_canonical_name
      self.canonical_name ||= canonicalize(self.name) if self.name
    end
  
    def canonicalize(x)
      x.downcase.  # something here
    end
  end
  </code></pre>
  
  <p>I need to fill in the "something here" to replace the accented characters.  Is there anything better than</p>
  
  <pre><code>x.downcase.gsub(/[àáâãäå]/,'a').gsub(/æ/,'ae').gsub(/ç/, 'c').gsub(/[èéêë]/,'e')....
  </code></pre>
  
  <p>And, for that matter, since I'm not on Ruby 1.9, I can't put those Unicode literals in my code.  The actual regular expressions will look much uglier.</p>