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 to 4.2.5.2 and do a bundle 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

Most upvoted comments

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.

curl 'http://my.dev.box:3000/en/search?x=✓'  # raises this error
curl 'http://my.dev.box:3000/en/search?x=1'  # works fine

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)