Ruby on Rails:从YAML文件加载种子数据 [英] Ruby on Rails: loading seed data from a YAML file

查看:72
本文介绍了Ruby on Rails:从YAML文件加载种子数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何使用YAML文件而不是seed.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 将它们加载到数据库中。 code>命令。可以使用固定装置进行的所有酷操作的完整文档在这里:

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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆