Runner in Ruby on Rails

 ̄綄美尐妖づ 提交于 2019-11-30 08:01:59

From the Rails Guides:

1.7 rails runner

runner runs Ruby code in the context of Rails non-interactively. For instance:

$ rails runner "Model.long_running_method"

You can also use the alias “r” to invoke the runner: rails r.

You can specify the environment in which the runner command should operate using the -e switch.

$ rails runner -e staging "Model.long_running_method"

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.

pastullo

You can put your Ruby file into the /lib folder and execute it through:

rails r lib/script.rb

That's it.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!