我用Rails 3.0.3,并有数据为我的类别表已经在数据库中,但想要从中创建一个种子文件。是否有任何rake任务,将产生seeds.rb格式我从这个表?
I'm using Rails 3.0.3 and have data for my "categories" table already in the database, but want to create a seed file from it. Is there any rake task that will generate the seeds.rb format for me from this table?
不知道任何现有的rake任务,但你可以尝试运行这样的事情在轨控制台和放大器;结果粘贴到您的seeds.rb文件
Not sure about any existing rake tasks, but you can try running something like this in the rails console & paste the results into your seeds.rb file
(警告:脏放大器;未经测试)
(warning: dirty & untested)
c = Category.all
c.each do |cat|
puts "Category.create(:name => '#{cat.name}')"
end
调整为任何其他领域,你可能有。
Adjust for any additional fields you may have.
希望这有助于。