How to run rake tasks from console?

后端 未结 5 412
南旧
南旧 2021-01-30 00:37

I want to invoke my rake task from console. Is it doable? if yes, how to do so?

I tried this on console:

require \         


        
5条回答
  •  天涯浪人
    2021-01-30 01:17

    Running your Rake tasks requires two steps:

    1. Loading Rake
    2. Loading your Rake tasks

    You are missing the second step.

    Normally this is done in the Rakefile, but you have to do it manually here:

    require 'rake'
    Rails.application.load_tasks # <-- MISSING LINE
    Rake::Task['my_task'].invoke
    

提交回复
热议问题