我可以以某种方式从我的 Rails 应用程序执行我的 db/seeds.rb 文件吗?
我正在构建一个演示,我希望非技术人员能够轻松设置和运行该演示。我构建了一个 seeds.rb 文件,其中包含大量演示数据。我希望能够通过页面链接提供管理员级操作,将 Rails 应用程序重置为已知状态。我不想为这些非技术示威者提供命令行和耙子,因为他们可能会搬起石头砸自己的脚。
我已经研究过在方法中使用 load 'db/seeds.rb' ,但这并不能完全达到我想要的效果。我知道我错过了一些东西,但是什么呢?
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.
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以调用Rails.application.load_seed。这就是 rake db:seed 所做的全部事情。
You can call
Rails.application.load_seed
. That's allrake db:seed
does.我更喜欢经典方法:
但我想,您也可以如上所述调用 Rails.application.load_seed 。
I prefer the classic method:
But I guess, that you can also call
Rails.application.load_seed
as mentioned.