5

I am encountering an incompatible character encoding error in production. I tried to reproduce it locally but had no luck. This is the error message:

A ActionView::Template::Error occurred in controller_name#action_name:

 incompatible character encodings: UTF-8 and ASCII-8BIT
 activesupport (3.0.5) lib/active_support/core_ext/string/output_safety.rb:80:in `concat'

config.encoding is already set to "utf-8" in application.rb. What's perplexing to me is that the issue persists only for some time around the Passenger restart and vanishes after some time. Further debugging into the exception backtrace gave me this:

activesupport (3.0.5) lib/active_support/core_ext/string/output_safety.rb:80:in `concat'
activesupport (3.0.5) lib/active_support/core_ext/string/output_safety.rb:80:in `concat'
actionpack (3.0.5) lib/action_view/template/handlers/erb.rb:14:in `<<'
app/views/web/controller_name/action_name.erb:98
<%currentUrl = request.url%>
Line 98: <a href="<%= raw currentUrl %>" id="xyz">

It is mentioned in "ActionView::Template::Error (incompatible character encodings: UTF-8 and ASCII-8BIT)" that ActionDispatch::Request might cause the problem, but I am clueless as to how the issue fixes itself after a while!

Community
  • 1
  • 1

2 Answers2

1

If you are getting this error with any text which is coming from database, then you need to use mysql2 in stead of mysql adapter in database.yml. And add mysql2 gem in your Gemfile too. This will solve your problem.

Neeraj Kumar
  • 6,045
  • 2
  • 31
  • 23
0

Try setting file encodings to UTF-8 by adding # encoding: UTF-8 to the top of the file(s).

Lenart
  • 3,101
  • 1
  • 26
  • 28
  • 1
    We have forced the encoding to UTF-8 and it worked. But, still could not find out how the issue fixed itself previously. –  Dec 26 '13 at 15:29