I have a Rails task: should I use script/runner or rake?

后端 未结 8 572
萌比男神i
萌比男神i 2020-12-07 16:08

For ad hoc Rails tasks we have a few implementation alternatives, chief among which would seem to be:

script/runner some_useful_thing
8条回答
  •  既然无缘
    2020-12-07 17:01

    The difference between them is that script/runner boots Rails whereas a Rake task doesn't unless you tell it to by making the task depend on :environment, like this:

    task :some_useful_task => :environment do
      # do some useful task
    end
    

    Since booting Rails is expensive, it might be worth skipping if you can avoid it.

    Other than that, they are roughly equivalent. I use both, but lately I've used script/runner executing a script separately more.

提交回复
热议问题