Search code examples
consolerake

How to run rake tasks from console?


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

I tried this on console:

require 'rake'
Rake::Task['my_task'].invoke

but it give me this error:

RuntimeError: Don't know how to build task

it's like the rake cannot found the task.

any help would be appreciated.

Thank you

Edit: I am using rails 2.3.5


Solution

  • 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