Run Rails commands outside of console

前端 未结 2 1958
执笔经年
执笔经年 2021-01-03 18:01

With my large application, the Rails console takes a while to load up. Is there a way to single commands more easily?

I\'d also like to be able to automate stuff, an

2条回答
  •  时光取名叫无心
    2021-01-03 18:16

    There are two main ways to run commands outside console:

    1. Rake task which depends on :environment
    2. rails runner (previously script/runner), eg:

      $ rails runner "query"
      

    Both are pretty well documented on the rails guide: http://guides.rubyonrails.org/command_line.html

    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.

提交回复
热议问题