I’m on rails 3.2.1 using postgres with pg 0.13.2 and haml 3.1.4.
DB encoding is “unicode” which I’m pretty sure is the same as “UTF-8″ to postgres
Meta tag has charset=utf-8 (on both form page and display page) and the form has accept-charset=”UTF-8”
I’m getting the “incompatible character encodings: ASCII-8BIT and UTF-8” error in my production environment (Heroku cedar) and I’ve tried a bunch of fixes so far but don’t really understand what’s going on. Dev environment doesn’t cause the problem.
The string causing the problem has an apostrophe copy/pasted from Word. If I remove the character everything renders fine but this is user submitted content so it’s sure to break again in the future.
From a Heroku consol, calling string.encoding.name returns “UTF-8” and using force_encoding(“UTF-8”) in the view makes no difference.
But, if I use a haml filter (like :markdown) on the string it all renders fine.
Also, changing the view to erb fixes the problem.
Any Ideas? It’s not really feasible to use filters everywhere and I want to get to the bottom of this.
tl;dr
Switched to the rdiscount parser and everything works now.
Longer Version:
I’m still not exactly sure what is going on but I know it’s in the parser (rpeg-markdown gem).
Another bit of text on the production page had a weird Word apostrophe and that seemed to be the issue. If I wrapped both strings in :markdown filters it all worked, but if either wasn’t in a filter I got the encoding error even though everything is utf-8.
I switched to rdiscount and now it works whether or not one (or both) of the blocks are wrapped in a :markdown filter.