Rails - Parse error in migration, but only on some systems
I've written a migration to populate a countries table with fairly static data.
It works fine on one of my machines (Rails 3.0.something, Ruby 1.9.something, Windows 7) but not on another (Rails 3.0.5, Ruby 1.8.7, OSX Snow Leopard). It gives me the following error:
/path_to_webapp/db/migrate/20110404132215_add_countries.rb:267: syntax error, unexpected kEND, expecting $end
It's not to do with the accented characters on some of the countries' names because the error still happens if I delete them all except Afghanistan and Zimbabwe, although I did have to convert the file to UTF8 to make it parse on the Windows box because it didn't like Côte d'Ivoire.
class AddCountries < ActiveRecord::Migration
# Use a copy of the Country class so we can add some without worrying about anything that may change on the model down the line
class Country < ActiveRecord::Base
end
def self.up
Countr开发者_StackOverflow中文版y.new({:name => "Afghanistan", :two_letter_code => "AF", :three_letter_code => "AFG"}).save
Country.new({:name => "Åland Islands", :two_letter_code => "AX", :three_letter_code => "ALA"}).save
Country.new({:name => "Albania", :two_letter_code => "AL", :three_letter_code => "ALB"}).save
Country.new({:name => "Algeria", :two_letter_code => "DZ", :three_letter_code => "DZA"}).save
end
def self.down
Country.all().destroy
end
end
You should put:
# encoding: utf-8
At the very top of your page.
I updated to Ruby 1.9.x and it worked fine.
精彩评论