How many rake tasks can be run at once in rails?

Why is my custom rake task in lib/tasks not discovered in Rails 3?

  • Build-in rake tasks work fine, but my new custom one in Project/lib/tasks/payments.rb doesn't get loaded: namespace :payments do desc "Tally payments at the end of the month" task :compute => :environment do BillingPeriod.compute_new_period end end $ rake payments:compute (in /Users/rob/Code/Apps/skyfarm) rake aborted! Don't know how to build task 'payments:compute' It works fine if I load the file application.rb: require 'lib/tasks/payments.rb' ...but it breaks other things: $ rails s ./lib/tasks/payments.rb:1: undefined method `namespace' for main:Object (NoMethodError)

  • Answer:

    It doesn't work because rake tasks are supposed to end in .rake, not .rb. So change payments.rb to payments.rake and it should work fine.

Anton Zolotov at Quora Visit the source

Was this solution helpful to you?

Other answers

Rakefile:# Add your own tasks in files placed in lib/tasks ending in .rake

Karteek Edamadaka

Related Q & A:

Just Added Q & A:

Find solution

For every problem there is a solution! Proved by Solucija.

  • Got an issue and looking for advice?

  • Ask Solucija to search every corner of the Web for help.

  • Get workable solutions and helpful tips in a moment.

Just ask Solucija about an issue you face and immediately get a list of ready solutions, answers and tips from other Internet users. We always provide the most suitable and complete answer to your question at the top, along with a few good alternatives below.