在控制台外运行Rails命令 [英] Run Rails commands outside of console
问题描述
使用我的大型应用程序,Rails控制台需要一段时间才能加载。
With my large application, the Rails console takes a while to load up. Is there a way to single commands more easily?
我也想自动化的东西, echoquery|
I'd also like to be able to automate stuff, and echo "query" | rails console
isn't a great way to do things.
推荐答案
在控制台外部运行命令的方法:
There are two main ways to run commands outside console:
- Rake任务取决于:environment
-
rails runner(以前的脚本/ runner),例如:
- Rake task which depends on :environment
rails runner (previously script/runner), eg:
$ rails runnerquery
$ rails runner "query"
这两种文件都在rails指南上有详细记录: http://guides.rubyonrails.org/command_line .html
Both are pretty well documented on the rails guide: http://guides.rubyonrails.org/command_line.html
btw:这两种方法仍然需要相同的时间作为控制台启动,但它们对非中间任务非常有用。
btw: both of these methods will still take the same time as a console to fire up, but they are useful for non-interative tasks.
这篇关于在控制台外运行Rails命令的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!