对于ad hoc Rails 任务,我们有几个实现替代方案,其中主要的似乎是:
For ad hoc Rails tasks we have a few implementation alternatives, chief among which would seem to be:
script/runner some_useful_thing和:
rake some:other_useful_thing我应该更喜欢哪个选项?如果有一个明显的最爱,那么我什么时候应该考虑使用另一个?如果从来没有,那么您为什么会认为它仍然存在于框架中而没有弃用警告?
Which option should I prefer? If there's a clear favourite then when, if ever, should I consider using the other? If never, then why would you suppose it's still present in the framework without deprecation warnings?
推荐答案它们之间的区别在于 script/runner 会引导 Rails 而 Rake 任务不会,除非您通过使任务依赖于:environment,像这样:
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由于启动 Rails 很昂贵,如果可以避免的话,可能值得跳过.
Since booting Rails is expensive, it might be worth skipping if you can avoid it.
除此之外,它们大致相同.我两者都使用,但最近我更多地使用 script/runner 单独执行脚本.
Other than that, they are roughly equivalent. I use both, but lately I've used script/runner executing a script separately more.
更多推荐
我有一个 Rails 任务:我应该使用 script/runner 还是 rake?
发布评论