Rails 3: how to undo rails generate

Posted by Arkham on July 29th, 2011

Have you ever run a

rails generate controller UsersController

and seen your app folder filled with useless files?

create app/controllers/users_controller_controller.rb
invoke erb
create app/views/users_controller
invoke test_unit
create test/functional/users_controller_controller_test.rb
invoke helper
create app/helpers/users_controller_helper.rb
invoke test_unit
create test/unit/helpers/users_controller_helper_test.rb
invoke assets
create app/assets/javascripts/users_controller.js.coffee
invoke scss
create app/assets/stylesheets/users_controller.css.scss

Eww, that’s gross.
To undo that rails generate, simply run:

rails destroy controller UserController

and rails will destroy all those ugly files for you!

remove app/controllers/users_controller_controller.rb
invoke erb
remove app/views/users_controller
invoke test_unit
remove test/functional/users_controller_controller_test.rb
invoke helper
remove app/helpers/users_controller_helper.rb
invoke test_unit
remove test/unit/helpers/users_controller_helper_test.rb
invoke assets
remove app/assets/javascripts/users_controller.js.coffee
invoke scss
remove app/assets/stylesheets/users_controller.css.scss

This entry was posted on Friday, July 29th, 2011 at 14:28 and is filed under thoughts. You can follow any responses to this entry through the RSS 2.0 feed. Both comments and pings are currently closed.

Tags: , ,

3 Responses to “Rails 3: how to undo rails generate”

  1. Rapture Says:

    Hi…
    nice article… I have a question…
    Why, when I generate a scaffold there isn’t the part from invoke assets and scss to the end??

    Thank you!!!

  2. Arkham Says:

    Probably because this is a Rails 3.1 test app: in Rails 3.1 jquery, coffescript and sass are the new defaults :)

  3. Abram Says:

    Don’t forget to remove your routes if you’ve run generate controller and provided action names as parameters