Disable Rake Commands in a Rails Project

Sometimes you want to disable some of the default rake tasks in a rails project. Here's a quick way to do just that.

I had a project where I wanted to limit the use of db rake tasks to keep anyone from accidentally deleting the database.

To delete a rake task, simply add this method to your Rakefile:



Here task is the name of your task.

If you want to do this multiple times, you can loop over your tasks like so:


def remove_task(task)

tasks = ['db:drop', 'db:reset', 'db:setup', 'db:rollback', 'db:seed']
tasks.each { |t| remove_task(t) }

Let's Connect

Keep Reading

How to Write a Custom Rake Task

Rake provides a great way to automate repetitive or complex tasks. Here's a look at creating a simple and a more complex task.

Apr 27, 2015

Connect to Multiple Databases in a Rake Task with Rails

Sometimes you need access to multiple database within a single rake task, for whatever reason. Here's how you do it.

Feb 17, 2015

How to Transition from CarrierWave to Dragonfly

It can be a process to move away from CarrierWave once you're already using it. Here's a step-by-step process to make it easy to transition to Dragonfly.

Jan 02, 2015