我想知道哪些是在Rails迁移中将记录添加到数据库表的首选方式。我读过奥拉·比尼的书(的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
这是非常干净的,但出于某种原因,不能正常工作的持续轨的版本...
问题是,你如何填充数据库与默认数据(如用户或东西)?
谢谢!
这几乎是我做什么,请包括您所收到的错误。 – 2009-01-06 03:24:55
完整的代码是这样的:http://pastie.org/pastes/251539 而错误是'CreateProductCategories不缺少常量ProductType' – 2009-01-06 04:14:31