Some Handy rake Tasks

Here are some handy rake tasks you may not be aware of and a quick description of what they do:

Database tasks

rake db:create– Will create a database to the settings defined in database.yml for the current environment.

rake db:create:all – Will create all of the databases defined in database.yml

rake db:drop – Will drop the database for the current environment.

rake db:drop:all – Will drop all of the databases defined in database.yml.

rake db:migrate:redo – Rolls back one migration and then re-runs the migration again (handy if you wan’t to make a quick change to the last migration).

rake db:migrate:reset – Drops all tables from the database and then rebuilds them using your migrations. This will delete all the entries from your current environment’s database.

rake db:reset – Drops all tables from the current environment’s database and then rebuilds them using schema.rb.

rake db:rollback – Rolls the database schema back to the previous version.

rake db:sessions:clear – Clears the sessions table if you’re using ActiveRecord::SessionStore

rake db:structure:dump – Dumps the current database structure to a .sql file into app/db/ (really handy for rebuilding your database elsewhere).

rake db:test:load – Recreates the test database from the current schema.rb

RDoc tasks

rake doc:app – Builds RDoc html files for your entire app in myapp/doc

rake doc:clobber_app – Removes the myapp/doc directory and all of its contents.

Gem tasks

rake gems – Lists all of the gems your app depends on (both the gems you have specified and their dependencies). The key here is simple: R = Rails framework gems, I = gems installed on the system and F = gems frozen in vendor/gems.

rake gems:install – Installs any gems your app requires that are not currently installed on the system

rake gems:unpack:dependencies – Unpacks all of the gems your app requires and their dependencies to your vendor/ folder. See tip #9 for more info.

Annotation tasks

(read this tip for more info on annotations)

rake notes – Lists all of your annotations

rake notes:todo – Lists all of your TODO annotations

rake notes:fixme – Lists all of your FIXME annotations

rake notes:optimize – Lists all of your OPTIMIZE annotations

rake notes:custom – Lists all of your custom annotations. You need to include the ANNOTATION variable with the name of your custom note type.

Rails tasks

rake rails:freeze:edgeFreeze to the latest version of rails

rake rails:freeze:gemsFreeze to the currently installed version of rails

Miscellaneous tasks

rake log:clear – Clears all of the .log files. Handy when your development log starts to get too large. See tip # 2 for keeping your production log under control.

rake routes – Displays all of the routes defined in config/routes.rb

rake stats – Shows a bunch of useful stats for your app including code-to-test ratio

rake tmp:cache:clear – Clears all of the files and directories in tmp/cache

That’s just a selection of the rake tasks available. To see the full list run

rake -T

Any others you think should be on this list? Leave a comment :)

Written by

Photo of Gavin Morrice
Gavin Morrice

Software engineer based in Scotland

Work with me

Need help with some code?

In my free time, I like to help people improve their code and skills on Codementor.
Contact me on Codementor