This project is archived and is in readonly mode.

#5748 ✓invalid

db:seed failing with multibyte characters

Reported by ClayH | October 1st, 2010 @ 04:03 PM

rake db:seed fails with multibyte characters in Rails 3.0.0.

Example seeds.rb file:

countries = Country.create([
                              {:name => 'Åland Islands', :iso_code => 'AX'},
                              {:name => 'Côte D\'Ivoire', :iso_code => 'CI'}])

This fails on both the Å and ô characters with the following error:

claymac:emr clay$ rake db:seed --trace
(in /Users/clay/rails/emr)
Invoke db:seed (first_time)
Invoke db:abort_if_pending_migrations (first_time)
Invoke environment (first_time)
Execute environment
Execute db:abort_if_pending_migrations
Execute db:seed
rake aborted!
/Users/clay/rails/emr/db/seeds.rb:2: invalid multibyte char (US-ASCII)
/Users/clay/rails/emr/db/seeds.rb:2: invalid multibyte char (US-ASCII)
/Users/clay/rails/emr/db/seeds.rb:2: syntax error, unexpected $end, expecting '}'
...                  {:name => 'Åland Islands', :iso_code => '...
...                               ^
/Users/clay/.rvm/gems/ruby-1.9.2-p0@up_to_date/gems/activesupport-3.0.0/lib/active_support/dependencies.rb:235:in `load'
/Users/clay/.rvm/gems/ruby-1.9.2-p0@up_to_date/gems/activesupport-3.0.0/lib/active_support/dependencies.rb:235:in `block in load'
/Users/clay/.rvm/gems/ruby-1.9.2-p0@up_to_date/gems/activesupport-3.0.0/lib/active_support/dependencies.rb:225:in `block in load_dependency'
/Users/clay/.rvm/gems/ruby-1.9.2-p0@up_to_date/gems/activesupport-3.0.0/lib/active_support/dependencies.rb:591:in `new_constants_in'
/Users/clay/.rvm/gems/ruby-1.9.2-p0@up_to_date/gems/activesupport-3.0.0/lib/active_support/dependencies.rb:225:in `load_dependency'
/Users/clay/.rvm/gems/ruby-1.9.2-p0@up_to_date/gems/activesupport-3.0.0/lib/active_support/dependencies.rb:235:in `load'
/Users/clay/.rvm/gems/ruby-1.9.2-p0@up_to_date/gems/activerecord-3.0.0/lib/active_record/railties/databases.rake:281:in `block (2 levels) in <top (required)>'
/Users/clay/.rvm/gems/ruby-1.9.2-p0@global/gems/rake-0.8.7/lib/rake.rb:636:in `call'

FYI, I used shift-option-A on a US keyboard to create the Å.

Comments and changes to this ticket

  • Szymon Nowak

    Szymon Nowak October 2nd, 2010 @ 08:51 PM

    Just add the following line as the first line in the file:

    # -*- coding: utf-8 -*-

    and it will work.

    You can probably set your editor to do add this line automatically for you, whenever there are some non-ASCII characters in the file.

  • Rohit Arondekar

    Rohit Arondekar October 6th, 2010 @ 07:21 AM

    • Importance changed from “” to “Low”

    ClayH, did the above fix the problem?

    P.S I thought in Ruby 1.9.2 all Ruby files were treated as UTF-8.

  • David Trasbo

    David Trasbo October 6th, 2010 @ 05:29 PM

    • State changed from “new” to “invalid”

    Confirmed, having # -*- coding: utf-8 -*- or alternatively # encoding: utf-8 as the first line solves the problem. db/seeds.rb is loaded using Ruby's load method, so ultimately it's a Ruby issue.

  • Ryan Bigg

    Ryan Bigg October 11th, 2010 @ 10:56 AM

    • Tag cleared.

    Automatic cleanup of spam.

Create your profile

Help contribute to this project by taking a few moments to create your personal profile. Create your profile »

<h2 style="font-size: 14px">Tickets have moved to Github</h2>

The new ticket tracker is available at <a href=""></a>