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

Tags: , ,