我编写了一个迁移,用相当静态的数据填充国家/地区表。
它在我的一台机器上运行正常(Rails 3.0.something,Ruby 1.9.something,Windows 7)但在另一台机器上运行不正常(Rails 3.0.5,Ruby 1.8.7,OSX Snow Leopard)。它给了我以下错误:
/path_to_webapp/db/migrate/20110404132215_add_countries.rb:267:语法错误,意外的kEND,期待$ end
这与某些国家/地区名称上的重音字符没有关系,因为如果我删除除阿富汗和津巴布韦以外的所有字符,错误仍然会发生,尽管我确实必须将文件转换为UTF8才能在Windows上进行解析因为它不喜欢科特迪瓦。
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
Country.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
答案 0 :(得分:2)
你应该把:
# encoding: utf-8
位于页面顶部。
答案 1 :(得分:0)
我更新到Ruby 1.9.x并且工作正常。