rails: Rails 4.2.5.2: ActionView::Template::Error (incompatible character encodings: UTF-8 and ASCII-8BIT)
Steps to reproduce
- Update Rails from
4.2.5.1
to4.2.5.2
and do abundle update rails
- Deploy Rails app to Heroku
- Some pages (which are views with Haml) give a
ActionView::Template::Error (incompatible character encodings: UTF-8 and ASCII-8BIT)
- A rollback to previous release on Heroku and the page is working again
Expected behavior
Page should work as normal
Actual behavior
error ActionView::Template::Error (incompatible character encodings: UTF-8 and ASCII-8BIT)
occurs
System configuration
Rails version: 4.2.5.2
Ruby version: 2.2.2
About this issue
- Original URL
- State: closed
- Created 8 years ago
- Comments: 17 (12 by maintainers)
Commits related to this issue
- squash! Force request.original_url to UTF-8 This was added to prevent integration specs failing in Ruby 2.0.0 with the following error when trying to include the locale_switcher partial: Encoding:... — committed to mysociety/alaveteli by lizconlan 7 years ago
- squash! Force request.original_url to UTF-8 This was added to prevent integration specs failing on Travis with Ruby 2.0.0 with the following error: Encoding::CompatibilityError: incompatible c... — committed to mysociety/alaveteli by lizconlan 7 years ago
- squash! Force request.original_url to UTF-8 This was added to prevent integration specs failing on Travis with Ruby 2.0.0 with the following error: Encoding::CompatibilityError: incompatible c... — committed to mysociety/alaveteli by lizconlan 7 years ago
- squash! Force request.original_url to UTF-8 This was added to prevent integration specs failing on Travis with Ruby 2.0.0 with the following error: Encoding::CompatibilityError: incompatible c... — committed to mysociety/alaveteli by lizconlan 7 years ago
- Force request.original_url to UTF-8 This was added to prevent integration specs failing on Travis with Ruby 2.0.0 with the following error: Encoding::CompatibilityError: incompatible character... — committed to mysociety/alaveteli by lizconlan 7 years ago
- Force request.original_url to UTF-8 This was added to prevent integration specs failing on Travis with Ruby 2.0.0 with the following error: Encoding::CompatibilityError: incompatible character... — committed to mysociety/alaveteli by lizconlan 7 years ago
- Force utf-8 encoding of request.original_url in og tags https://github.com/rails/rails/issues/23978 — committed to dylanfisher/forest by dylanfisher 5 years ago
It’ll depend on how you’re using it (and if it’s the cause of your error - the ASCII-8BIT data may be from something else) but you can see what I did in these commits:
https://github.com/alphagov/e-petitions/commit/1f63d9e179ea95bde1922d6b14ea9405547a2418 https://github.com/alphagov/e-petitions/commit/dd5c6ca1e0b1ac829272f1529d481a4604c3d0fa
It’ll mean you’ll get weird characters sometimes but that’s better than the page blowing up.
Thanks @pixeltrix. Your examples and suggestions helped a lot.
I managed to do more hunting, and eventually discovered somewhere we used
request.url
(some meta tag for facebook,og:url
…).Somehow view traces aren’t the most specific, which makes tracing those kinds of bugs much harder. But at least I found it! Thanks again.
I’m having a similar issue to @manfe. The odd thing is that the error depends on the request itself.
We have a template with a few UTF-8 characters, e.g.
ä
. It renders just fine most of the time, but some times fails, depending on the request params.i.e.
removing the UTF-8 characters from the template renders fine in both cases.
Tried various changes like adding
# encoding: UTF-8
on the template, using.force_encoding('UTF-8')
on the string and various other hacks, but nothing seems to resolve this.(ruby 2.2.2 / rails 4.2.5.2)