I use Rails 3.2 and the CSV library to import CSV files.
I use it like this:
CSV.foreach(open(csv_url), :headers => true) do |p|
When I run it on my local computer it works fine, but for some reason it fails for some records on Heroku with the error:
incompatible character encodings: ASCII-8BIT and UTF-8
It fails in a method I’ve defined that simply appends two strings:
def name_and_brand
"#{name} #{brand.name}"
end
It only fails on some records though, not all.
I’ve read lots of information about this but I still haven’t figured out how to solve it.
If I simply output the encoding of the text I’m parsing it says on my local computer that it is UTF-8, but on Heroku it says ASCII-8BIT.
If I run "a".encoding in the console it outputs UTF-8 and Heroku outputs UTF-8 too.
What I’ve tried so far
# in application.rb
config.encoding = "utf-8"
# in environment.rb
Encoding.default_external = Encoding::UTF_8
Encoding.default_internal = Encoding::UTF_8
# in other files
# encoding: UTF-8
One difference I’ve found is that Heroku use Ruby 1.9.2 and I use 1.9.3 on my local machine. Could that be it?
Any ideas what I can try more?
EDIT
I found out that you can explicitly choose ruby version on heroku by adding ruby "1.9.3" in the gemfile. Seems to have fixed my issue.
I had to explicitly change ruby version to 1.9.3 by adding
ruby "1.9.3"in my Gemfile