I built an app, I add articles, I view articles, everything is fine on that side of things.
However, I’ve been setting up sending the articles via email and I came up against encoding issues. In particular the £ character, it would always create an error.
My database is set to UTF-8 Unicode and my Rails app has config.encoding = "utf-8" set.
However, I discovered this:
> Article.first.title.encoding.name
=> "ASCII-8BIT"
In the end I did a workaround to the get the emails to work (article.title.force_encoding("utf-8").gsub(/\xC2\xA3/, "£")) but it feels a bit like a hack to me.
Is there something I’ve missed? Some other setting I haven’t taken into account? How do I set up encoding in Rails 3 correctly?
If you’re adding these articles yourself (i.e. they’re not coming from somewhere else, like a scraper), and you’re getting this error, it sounds like your browser is sending the wrong encoding to the app. Try adding
<meta charset="utf-8">to the<head>of your document.