在 Ruby on Rails 中运行 [英] Runner in Ruby on Rails
问题描述
什么是脚本/运行器?
什么是跑步者?
如何在 Ruby 文件中使用 runner?
How do I use runner on a Ruby file?
在命令提示符下输入的所有命令是什么?
What are all the commands typed out on the command prompt?
顺便说一下,我使用的是 Windows.
I'm using Windows by the way.
推荐答案
来自 Rails 指南:
runner
在 Rails 上下文中以非交互方式运行 Ruby 代码.为了实例:
1.7
rails runner
runner
runs Ruby code in the context of Rails non-interactively. For instance:
$ rails runner "Model.long_running_method"
您还可以使用别名r"来调用运行程序:rails r
.
You can also use the alias "r" to invoke the runner: rails r
.
你可以指定运行命令应该在的环境使用 -e
开关操作.
You can specify the environment in which the runner command should
operate using the -e
switch.
$ rails runner -e staging "Model.long_running_method"
任何要运行的代码都必须作为 Rails 应用程序的一部分加载,即在 app/
或 lib/
等位置.
Any code to be run must be loaded as a part of your Rails app, i.e. either in app/
or lib/
, among other places.
这篇关于在 Ruby on Rails 中运行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!