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
Go to Websites & Domains and click Ruby. After gems installation you can try to run a Rake task by clicking Run rake task. In the opened dialog, you can provide some parameters and click OK - this will be equivalent to running the rake utility with the specified parameters in the command line.
You can get a list of Rake tasks available to you, which will often depend on your current directory, by typing rake --tasks . Each task has a description, and should help you find the thing you need.
Rake is a software task management and build automation tool created by Jim Weirich. It allows the user to specify tasks and describe dependencies as well as to group tasks in a namespace. It is similar in to SCons and Make.
Running your Rake tasks requires two steps:
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
The easiest way to do it is to run %x[command] from the irb. I'm not sure if what you want to achieve though.
%x[rake db:migrate]
EDIT: I highly recommend to use .invoke
as Daniel says in the accepted answer.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With