From: Luis Lavena Date: 2010-11-04T11:20:17+09:00 Subject: Re: Ruby 1.9.2 with Rails 3.0.1 On Nov 3, 10:47 pm, Bharat Ruparel wrote: > Sorry about that.  Was tired towards the end of the day and therefore a > not so bright post.  I owe it to the group to clear things up. > > To make a long story short, it was the character encoding problem with > ruby 1.9.2. > > The following is a snippet of code from seeds.rb file > > courses = [ {:title => 'Principles of Good Cooking 1', :course_code => > 'PGC1', >   :lessons => [{:title => 'Getting Started'}, >     {:title => 'Saut√©ing', >       :topics => [ {:tag => "Lecture", :title => "Introduction to > Saut√©ing", >           :pages => [ {:title => "Video Lecture" }] }, > > See that 'Saut√©ing', string? > > That is Sauteing with funny symbols over e for french.  That was causing > the > > rake db:seed command to fail (throw exception) as follows: > > bruparel:~/school > → rake db:seed > (in /Users/bruparel/school) > rake aborted! > /Users/bruparel/school/db/seeds.rb:3: invalid multibyte char (US-ASCII) > /Users/bruparel/school/db/seeds.rb:3: invalid multibyte char (US-ASCII) > /Users/bruparel/school/db/seeds.rb:3: syntax error, unexpected $end, > expecting '}' >     {:title => 'Sautéing', >                       ^ > > The solution was to put the following line at the top of this file > (seeds.rb) > > # encoding: utf-8 > > If someone can articulate some simple rules for character encoding in > Ruby 1.9.2 p0 and Rails 3.0.1 environment, that will be quite useful. > Ruby interprets each file 'encoding' or magical comments to decide which encoding is going to use for that particular file. If the file lacks encoding it assumes the one provided by Encoding.default_external, which in your case seems US-ASCII. sqlite3-ruby, since 1.3.0 is quite aware of character encoding and should work properly. If Rails is not doing the right thing, that is another question. You can double check that doing: ActiveRecord::Base.connection.execute 'PRAGMA encoding' That can tell you which encoding SQLite3 was open. Further than that and about Rails specific issues, ask Rails-Talk: http://groups.google.com/group/rubyonrails-talk -- Luis Lavena