Ruby on Rails:从 YAML 文件加载种子数据 [英] Ruby on Rails: loading seed data from a YAML file
本文介绍了Ruby on Rails:从 YAML 文件加载种子数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何使用 YAML 文件代替seeds.rb 将初始数据加载到数据库中?
How do I use a YAML file instead of seeds.rb to load the initial data into a database?
推荐答案
查看 Ruby on Rails 固定装置指南:
Check out the Ruby on Rails Guide to fixtures:
http://guides.rubyonrails.org/testing.html#the-low-down-on-fixtures
通常,您可以在 test/
目录中创建 YAML 夹具文件,然后使用 rake db:fixtures:load
命令将它们加载到您的数据库中.关于你可以用灯具做的所有很酷的事情的完整文档在这里:
Generally, you can create YAML fixture files in the test/
directory and then load them into your database using the rake db:fixtures:load
command. The full documentation on all the cool things you can do with fixtures is here:
http://api.rubyonrails.org/classes/Fixtures.html
这篇关于Ruby on Rails:从 YAML 文件加载种子数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文