I have a Rails app using Postgres. I have a Document
model that has a name
attribute. Some names contain accented characters. A couple of example names:
Condições Para Aplicação Da Lei
Considerações Introdutórias
I am querying for models with a specific name using:
document = Document.where(name: "Example Document Name").first
So long as the name doesn't contain special characters, this works fine, however as soon as I use a name containing any accented characters, the query returns nil.
$ Document.all
$ #<Document id: 1, name: "Foo" ... >
$ #<Document id: 1, name: "Considerações Introdutórias" ... >
$ Document.where(name: "Foo").first
$ #<Document id: 1, name: "Foo" ... >
$ Document.where(name: "Considerações Introdutórias").first
$ # nil
Why is this query failing when the name contains special characters?
In my config/application.rb
:
config.encoding = "utf-8"
In my `config/database.yml':
encoding: utf8