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
Other answers
Rakefile:# Add your own tasks in files placed in lib/tasks ending in .rake
Karteek Edamadaka
Related Q & A:
- Is there email validation baked in to Rails 3?Best solution by coverhound.com
- Is there any Custom FW 3.40?Best solution by forums.exophase.com
- How can I custom firmware my psp 3.80 slim?Best solution by Yahoo! Answers
- How do I put a custom PSP firmware when I have 3.71 firmware?Best solution by krizka.net
- Downgrade fat 3.95 PSP to Custom Firmware?Best solution by Yahoo! Answers
Just Added Q & A:
- How many active mobile subscribers are there in China?Best solution by Quora
- How to find the right vacation?Best solution by bookit.com
- How To Make Your Own Primer?Best solution by thekrazycouponlady.com
- How do you get the domain & range?Best solution by ChaCha
- How do you open pop up blockers?Best solution by Yahoo! Answers
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.