在控制台外运行Rails命令 [英] Run Rails commands outside of console

查看:134
本文介绍了在控制台外运行Rails命令的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用我的大型应用程序,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:


  1. Rake任务取决于:environment

  2. rails runner(以前的脚本/ runner),例如:

  1. Rake task which depends on :environment
  2. 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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆