Multiple encodings should not be used simultaneously in Rails.
We have two html partial templates with the correct 1.9 encoding magic:
- one in Shift-JIS
- one in EUC-JP
and a layout file with UTF-8 content-type.
This cannot be fixed because Ruby 1.9 considers the encodings incompatible and won’t allow concatenation without first converting each string into a common encoding (Encoding::CompatibilityError).
The example.rb shows what works and what doesn’t.
- Encode strings to a common encoding just before concatenation.
- Do not allow strings in incompatible character sets in Rails (where concatenation can occur).
- error occurs too far from the source
- performance hit when rendering templates
- environment setup problems are hidden
+ easy workaround in output_safety (for templates)
- more work than solution 1
+ proper solution
This is why I believe the policy would be to attempt to convert all strings from external sources to a common encoding, to Encoding::default_internal (or Encoding::default_external if nil) for example.