我想知道在Rails迁移中向数据库表添加记录的首选方式是什么.我在Ola Bini的书(JRuby On Rails)上读到他这样做:
class CreateProductCategories < ActiveRecord::Migration
#defines the AR class
class ProductType < ActiveRecord::Base; end
def self.up
#CREATE THE TABLES...
load_data
end
def self.load_data
#Use AR object to create default data
ProductType.create(:name => "type")
end
end
这很好,很干净,但由于某些原因,在rails的最新版本上不起作用...
问题是,如何使用默认数据(如用户或其他数据)填充数据库?
谢谢