Removing a model from your rails project

Posted on Nov 24, 2010

During the work on a project I created a model. Right after clicking the Enter key I realized that I didn’t need it and wanted to roll back.

Because I am using GIT, I could of course have done this using it, but I wanted to do it using a Rails command.

Turns out, there’s a command to do this (if you haven’t migrated the db yet).

The command is as follows:

[shell]

script/destroy model contact

[/shell]

This will remove all of the files that were added by this command.

[shell]

script/generate model contact user_id:integer type:integer

[/shell]

Nice to know you can either do this with GIT or with Rails. Obviously the best solution is to think before you click Enter but it’s nice to know nevertheless.