我可以从我的 rails 应用程序中以某种方式执行我的 db/seeds.rb 文件吗? [英] Can I somehow execute my db/seeds.rb file from my rails app?
问题描述
我正在构建一个演示,我想让非技术人员很容易地设置和运行演示.我已经建立了一个包含大量演示数据的seeds.rb 文件.我希望能够通过页面链接提供管理员级别的操作,将 rails 应用程序重置为已知状态.我不想为这些非技术示威者提供命令行和耙子,因为他们可能会用脚射击自己.
I am building a demo, and I want to make it very easy for a non-technical person to set up and run the demo. I have built a seeds.rb file with lots of demo data in it. I want to be able to reset the rails app to a known state by providing an administrator-level action via a page link. I don't want to provide these non-tech demonstrators with a command line and rake, because they might shoot themselves in the foot.
我研究过在一个方法中使用 load 'db/seeds.rb',但这并不能完全满足我的要求.我知道我遗漏了一些东西,但是什么?
I have looked into using load 'db/seeds.rb' within a method, but that doesn't quite do what I want. I know I am missing something, but what?
推荐答案
您可以调用 Rails.application.load_seed
.这就是 rake db:seed
所做的.
You can call Rails.application.load_seed
. That's all rake db:seed
does.
这篇关于我可以从我的 rails 应用程序中以某种方式执行我的 db/seeds.rb 文件吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!