How to reverse a 'rails generate' How to reverse a 'rails generate' ruby ruby

How to reverse a 'rails generate'


rails destroy controller lalalarails destroy model yadayadarails destroy scaffold hohoho

Rails 3.2 adds a new d shortcut to the command, so now you can write:

rails d controller lalalarails d model yadayadarails d scaffold hohoho


It's worth mentioning the -p flag here ("p" for pretend).

If you add this to the command it will simply do a "test" run and show you what files will be deleted without actually deleting them.

$ rails d controller welcome -p  remove  app/controllers/welcome_controller.rb  invoke  erb  remove    app/views/welcome  invoke  test_unit  remove    test/controllers/welcome_controller_test.rb  invoke  helper  remove    app/helpers/welcome_helper.rb  invoke    test_unit  remove      test/helpers/welcome_helper_test.rb  invoke  assets  invoke    coffee  remove      app/assets/javascripts/welcome.js.coffee  invoke    scss  remove      app/assets/stylesheets/welcome.css.scss

If you're happy with it, run the command again without the -p flag.


rails destroy controller Controller_name was returning a bunch of errors. To be able to destroy controller I had to remove related routes in routes.rb. P.S. I'm using rails 3.1