0
votes

I'm trying to deploy an application on an Ubuntu 14.02 server with NGINX and PUMA and when I try to access static pages on the server with characters in brazilian portuguese and WITHOUT access to the database, the page is not showed and the following error gets logged:

ActionView::Template::Error (incompatible character encodings: ASCII-8BIT and UTF-8)

I read a lot of posts/answers regarding this error and tried everything.

Ruby version: ruby 2.1.3p242 (2014-09-19 revision 47630) [x86_64-linux] Rails version: Rails 4.2.4

The command locale in the server return the following:

LANG=en_US.UTF-8
LANGUAGE=en_US.UTF-8
LC_CTYPE="en_US.UTF-8"
LC_NUMERIC="en_US.UTF-8"
LC_TIME="en_US.UTF-8"
LC_COLLATE="en_US.UTF-8"
LC_MONETARY="en_US.UTF-8"
LC_MESSAGES="en_US.UTF-8"
LC_PAPER="en_US.UTF-8"
LC_NAME="en_US.UTF-8"
LC_ADDRESS="en_US.UTF-8"
LC_TELEPHONE="en_US.UTF-8"
LC_MEASUREMENT="en_US.UTF-8"
LC_IDENTIFICATION="en_US.UTF-8"
LC_ALL=en_US.UTF-8

My application.rb contains the line:

config.encoding = "utf-8"

My environment.rb contais the lines:

Encoding.default_external = Encoding::UTF_8
Encoding.default_internal = Encoding::UTF_8

I already putted the # encoding: "utf-8" on top of my html.erb files without success.

1

1 Answers

1
votes

Check that the offending source files actually use the UTF-8 encoding (for example, Textmate allows to save the file using various encodings). Check whether the file is actually recognized by the system as UTF, running file /path/to/something should return UTF-8.

Also if you have just a few of those badly encoded strings you can try something like this:

the_bad_string.dup.force_encoding("UTF-8")

This should convert whatever it was to UTF.