Posted in Workflow

Rake tasks

You can see a full list of the tasks rake can automate by typing

rake -T

but you’re also able to create custom tasks of your own that you can run using rake.

You write the whole thing in ruby, and you do it in your project’s lib/tasks directory. Create a new file there, named whatever you like, and give it the filetype/ending .rake

You then add tasks to the file, which’ll be run whenever you run the task. eg:

task :greet do
  puts "howdy"

This means you can now run this task from the terminal, with the command:

rake greet

You can also use namespacing to get the little notice:the:colons effect (eg db:migrate). For example

namespace :annotate do
   desc "annotate your models!"
   task :models, :needs => :environment do |t, args|
      exec "annotate --exclude tests,fixtures -p before"

This task can now be run by typing:

rake annotate:models

Read more here:


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s