Friday, 20 April 2012

Undoing a Rails generate

To undo an action in Rails (generation of a scaffold, model, migration, etc), you can use
 rails destroy  

For example, generating and then destroying a controller called Posts would look like this:

 $ rails generate controller Posts  
    create app/controllers/posts_controller.rb  
    invoke erb  
    create  app/views/posts  
    invoke test_unit  
    create  test/functional/posts_controller_test.rb  
    invoke helper  
    create  app/helpers/posts_helper.rb  
    invoke  test_unit  
    create   test/unit/helpers/posts_helper_test.rb  
    invoke assets  
    invoke  coffee  
    create   app/assets/javascripts/posts.js.coffee  
    invoke  scss  
    create   app/assets/stylesheets/posts.css.scss  

$ rails destroy controller Posts  
    remove app/controllers/posts_controller.rb  
    invoke erb  
    remove  app/views/posts  
    invoke test_unit  
    remove  test/functional/posts_controller_test.rb  
    invoke helper  
    remove  app/helpers/posts_helper.rb  
    invoke  test_unit  
    remove   test/unit/helpers/posts_helper_test.rb  
    invoke assets  
    invoke  coffee  
    remove   app/assets/javascripts/posts.js.coffee  
    invoke  scss  
    remove   app/assets/stylesheets/posts.css.scss  

No comments:

Post a Comment

Please leave a comment if you find this blog helpful or interesting! I'd love to hear from you!