Monday, September 17, 2012

Delete controller, view, models automatically from Rails Application

In Ruby on Rails, it is quite easy to create a new model view and controller using the scaffold command. Apart from the mentioned MVC this command also creates many other files like migration which proves quite helpful for creating a new ruby application.

However there are times when you want to delete a controller / view / model from the application along with files that are automatically created with the scaffold / generate command like fixture, spec etc and the simple command to ease your task is destroy (Rails3). Use it like

rails destroy controller controller_name
e.g. rails destroy controller categories

Here we can replace controller with view or model to delete an appropriate object.

Note that while specifying controller name just specify the name of controller not controller file name like here categories not categories_controller.rb. This command will delete categories controller, model, view and other background stuff. Here is the list of task done by the command fired in example.

No comments:

Post a Comment