将种子数据添加到开发数据库中进行测试
我有几个表,我想以尊重和说明它们关系的方式向其中添加大约 10 行数据。
如何将种子数据(虚拟数据)添加到我的应用程序的开发数据库中以进行测试?
我希望有人能给我指出一种对 Rails 友好的方法来做到这一点。是否有一种简单的方法可以在每个表透视控制器中创建 CRUD 方法?
I have a few tables that I would like to add about 10 rows of data to, in a manner that respects and illustrates their relationships.
How can I add seed data (dummy data) to my applications' development database for testing?
I'm hoping someone could point me to a rails friendly method for doing this.Is there an easy way to make the CRUD methods in each table perspective controllers?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

这就是 db/seeds.rb 文件的用途。
您可以使用 rake db:seed 执行它
seeds.rb 的默认内容
您可以在其中使用 ruby,因此插入 10 个用户:
This is what the
db/seeds.rb
file is for.You can execute it with rake db:seed
The default contents of seeds.rb
You can use ruby in this, so to insert 10 users: