This might sound minor, but it s been driving me nuts. Since releasing an application to production last Friday on Ruby 1.9, I ve been having lots of minor exceptions related to character encodings. Almost all of it is some variation on:
Encoding::CompatibilityError: incompatible character encodings: ASCII-8BIT and UTF-8
We have an international user base so plenty of names contain umlauts, etc. If I fix the templates to use force_encoding in a bunch of places, it pops up in the flash message helper. Et cetera.
At the moment it looks like I ve nailed down all the ones I knew about, by patching ActiveSupport s string concatenation in one place and then by setting # encoding: utf-8
at the top of every one of my source files. But the feeling that I might have to remember to do that for every file of every Ruby project I ever do from now on, forever, just to avoid string assignment problems, does not sit well in my stomach. I read about the -Ku switch but everything seems to warn that it s for backwards compatibility and might go away at any time.
So my question for 1.9-experienced folks: is setting #encoding
in every one of my files really necessary? Is there a reasonable way to do this globally? Or, better, a way to set the default encoding on non-literal values of strings that bypass the internal/external defaults?
Thanks in advance for any suggestions.