Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to run rake task?

I have an existing .rake file. It used to have one task and I added one more task to the existing rake file.

But when I try to run, it throws an error:

rake aborted!
Don't know how to build task ___ 

abc.rake file:

namespace abcd
  namespace abcde
    task pqr do
      ------------------
    end

    task mno do ( new task which I added)
     ---------------------
    end
  end
end

But when I used command: rake abcd:abcde:mno -- it showed above error

So I used rake -T -A , I am able to see the rake task abcd:abcde:pqr but am unable to see the other one.

I am new to rails. Please help me out.

Thanks in advance.

like image 243
vikas vellanki Avatar asked Jun 11 '15 04:06

vikas vellanki


People also ask

How do I run a rake?

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.

What are Rake tasks?

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.

How do I list a rake task?

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.


1 Answers

In Rails 6.x you have to use rails instead of rake. The example from user400617 above

namespace :abcd do
  namespace :abcde do

     task :pqr do
       puts 'Inside PQR'
     end

     task :new_added_task do
       puts 'Inside New Added Task'
     end

     task :mno => [:new_added_task]  do
       puts 'Inside Mno'
     end

   end
end

would be run like this

rails abcd:abcde:pqr           #  Output => Inside PQR 

rails abcd:abcde:mno           #  Output => Inside New Added Task
                              #            Inside Mno

rails abcd:abcde:new_added_task  # Output => Inside New Added Task

Took me a while to figure this out.

like image 57
Victor Avatar answered Oct 04 '22 21:10

Victor