1

When I try to run heroku run rake db:migrate in my application, I get the following error

"\xC4" from ASCII-8BIT to UTF-8

with a stacktrace of

/app/.bundle/gems/ruby/1.9.1/gems/rake-0.9.2.2/lib/rake/application.rb:150:in `write'
/app/.bundle/gems/ruby/1.9.1/gems/rake-0.9.2.2/lib/rake/application.rb:150:in `puts'
/app/.bundle/gems/ruby/1.9.1/gems/rake-0.9.2.2/lib/rake/application.rb:150:in `display_error_message'
/app/.bundle/gems/ruby/1.9.1/gems/rake-0.9.2.2/lib/rake/application.rb:142:in `rescue in standard_exception_handling'
/app/.bundle/gems/ruby/1.9.1/gems/rake-0.9.2.2/lib/rake/application.rb:132:in `standard_exception_handling'
/app/.bundle/gems/ruby/1.9.1/gems/rake-0.9.2.2/lib/rake/application.rb:88:in `top_level'
/app/.bundle/gems/ruby/1.9.1/gems/rake-0.9.2.2/lib/rake/application.rb:66:in `block in run'
/app/.bundle/gems/ruby/1.9.1/gems/rake-0.9.2.2/lib/rake/application.rb:133:in `standard_exception_handling'
/app/.bundle/gems/ruby/1.9.1/gems/rake-0.9.2.2/lib/rake/application.rb:63:in `run'
/app/.bundle/gems/ruby/1.9.1/gems/rake-0.9.2.2/bin/rake:33:in `'
/app/.bundle/gems/ruby/1.9.1/bin/rake:19:in `load'
/app/.bundle/gems/ruby/1.9.1/bin/rake:19:in `'

I've tried setting encoding manually in config/environment.rb via

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

But it doesn't seem to help. The problem might be, that I'm using slim as a templating engine with many unicode characters directly in the templates, but I'm not sure if there's a better way of doing that.

John Bachir
  • 22,495
  • 29
  • 154
  • 227
Jakub Arnold
  • 85,596
  • 89
  • 230
  • 327
  • If you are running on Ruby 1.9, you may have to set the encoding at the top of the template files with the irregular unicode characters like [mentioned here](http://yehudakatz.com/2010/05/05/ruby-1-9-encodings-a-primer-and-the-solution-for-rails/). Try putting this line at the top of those files: `# encoding: UTF-8` – Batkins Jan 10 '12 at 01:40
  • [Here is a link](http://stackoverflow.com/questions/3223518/ruby-1-9-sinatra-incompatible-character-encodings-ascii-8bit-and-utf-8/3224119#3224119) to another very similar question that was asked on StackOverflow a while ago. [This post might also help you](http://stackoverflow.com/questions/2095525/can-i-set-the-default-string-encoding-on-ruby-1-9) – Batkins Jan 10 '12 at 01:44

1 Answers1

1

Simply add this to the top of your file

# encoding: UTF-8

this error is frequent with migration when you insert data. For exemple I've got this with a simple migration adding Québec

Province.create(:name => 'Québec (Canada)')
Supernini
  • 591
  • 5
  • 8