Skip to main content

Rails Envy: Ruby on Rails Rake Tutorial (aka. How rake turned...

Popularity Report

Total Popularity Score: 0

Loading...
Loading...
Loading...
Loading...
Loading...
Loading...

Rank

Groups (1)

  • rubyonrails

    Ruby on Rails

    46 members,171 bookmarks

    Ruby on Rails Web Development Framework resources

Bookmark History

Saved by 41 people (11 private), first by anonymouse user on 2007-06-11


Public Sticky notes

Task creation - With every large application you almost always end up writing scripts that you can run from the command line. You might want to clear the cache, run a maintenance task, or migrate the database. Rather than creating 10 separate shell scripts (or one big complex one) you can create a single "Makefile" in which you can organize things by task. Tasks then can be run by typing something like "make stupid" (which runs the stupid task).

Highlighted by draconid

you start to notice that some tasks might partially repeat themselves

Highlighted by mrhsudiigo

Rake Namespaces

Once you become an alcoholic and you're using lots of Rake tasks, you may need a better way to categorize them. This is where namespaces come in. If I were to use namespaces in the above example, it might look like this:

Highlighted by alleylab

As you can see, there is only one step to get access to your models, the "=> :environment" thing:

  1. task(:send_expire_soon_emails => :environment) do

To run this task on my development db I would run "rake utils:send_expire_soon_emails". If I wanted to run this on my production database, I would run "rake RAILS_ENV=production utils:send_expire_soon_emails".

Highlighted by vincent

As you can see, there is only one step to get access to your models, the "=> :environment" thing:

Highlighted by vincent

If I then wanted this to run nightly on my production database at midnight, I might write a cronjob that looks something like this:


0 0 * * * cd /var/www/apps/rails_app/ && /usr/local/bin/rake RAILS_ENV=production utils:send_expire_soon_emails

Pretty convenient!

Highlighted by vincent