Ruby-on-rails 我可以从我的 rails 应用程序中以某种方式执行我的 db/seeds.rb 文件吗?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/5212351/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Can I somehow execute my db/seeds.rb file from my rails app?
提问by explainer
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.
我正在构建一个演示,我想让非技术人员很容易地设置和运行演示。我已经建立了一个包含大量演示数据的seeds.rb 文件。我希望能够通过页面链接提供管理员级别的操作,将 rails 应用程序重置为已知状态。我不想为这些非技术示威者提供命令行和耙子,因为他们可能会用脚射击自己。
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?
我已经研究过在方法中使用 load 'db/seeds.rb' ,但这并不完全符合我的要求。我知道我错过了一些东西,但是什么?
回答by idlefingers
You can call Rails.application.load_seed. That's all rake db:seeddoes.
你可以打电话Rails.application.load_seed。就是rake db:seed这样。

