incompatible character encodings: ASCII-8BIT and UTF-8
I have a suspicion that you either copy/pasted a part of your Haml template into the file, or you're working with a non-Unicode/non-UTF-8 friendly editor.
See if you can recreate that file from the scratch in a UTF-8 friendly editor. There are plenty for any platform and see whether this fixes your problem. Start by erasing the line with #content
and retyping it manually.
ActionView::Template::Error (incompatible character encodings: UTF-8 and ASCII-8BIT)
After doing some debugging I found out the issue occurs when using the ActionDispatch::Request object which happens to have strings that are all coded in ASCII-8BIT, regardless of whether my app is coded in UTF-8 or not. I do not know why this only happens when using a production server on Linux, but I'm going to assume it's some quirk in Ruby or Rails since I was unable to reproduce this error locally. The error occurred specifically because of a line like this:
@current_path = request.env['PATH_INFO']
When this instance variable was printed in the HAML template it caused an error because the string was encoded in ASCII-8BIT instead of UTF-8. To solve this I did the following:
@current_path = request.env['PATH_INFO'].dup.force_encoding(Encoding::UTF_8)
Which forced @current_path
to use a duplicated string that was forced into the proper UTF-8 encoding. This error can also occur with other request related data like request.headers
.
Related Topics
Ruby Read CSV File as Utf-8 And/Or Convert Ascii-8Bit Encoding to Utf-8
Escaping Single and Double Quotes in a String in Ruby
Why Can't Singleton Methods Be Defined on Symbols or Fixnums
How to Download via Http Only Piece of Big File with Ruby
Ruby SQLite3 Installation SQLite3_Libversion_Number() MACos Sierra
Ruby Craziness: Class VS Object
Rvm Ruby 1.9.1 Install Can't Locate Zlib But Its Runtime and Dev Library Are There
Rails and Os X: How to Install Rmagick
Yaml How Many Spaces Per Indent
Why Does Array.Slice Behave Differently for (Length, N)
Looping Through an Array with Step
Select Arrays Between Date Ranges with Ruby