Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Rails how to run rake task

How do I run this rake file in terminal/console?

my statistik.rake in lib/tasks

desc "Importer statistikker" namespace :reklamer do   task :iqmedier => :environment do     ...   end   task :euroads => :environment do     ...   end   task :mikkelsen => :environment do     ...   end   task :orville => :environment do     ...   end end 
like image 913
Rails beginner Avatar asked Apr 12 '11 21:04

Rails beginner


2 Answers

You can run Rake tasks from your shell by running:

rake task_name 

To run from from Ruby (e.g., in the Rails console or another Rake task):

Rake::Task['task_name'].invoke 

To run multiple tasks in the same namespace with a single task, create the following new task in your namespace:

task :runall => [:iqmedier, :euroads, :mikkelsen, :orville] do   # This will run after all those tasks have run end 
like image 187
Andrew Marshall Avatar answered Sep 24 '22 06:09

Andrew Marshall


Rake::Task['reklamer:orville'].invoke 

or

Rake::Task['reklamer:orville'].invoke(args) 
like image 41
Luke W Avatar answered Sep 25 '22 06:09

Luke W