How to reverse a 'rails generate'

前端 未结 17 1266
一个人的身影
一个人的身影 2020-12-02 03:10

I want to delete all the files it created and roll back any changes made, but not necessarily to the database, but more to the config files.

I\'d like to automatical

相关标签:
17条回答
  • 2020-12-02 03:56

    We use generate as rails generate app. So regenerating any generate statement can be reversed using destroy statement. Just replace generate with destroy i.e. rails generate app can be written as rails destroy app' rails generate ____asrails destroy ____`

    0 讨论(0)
  • 2020-12-02 04:02

    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.

    0 讨论(0)
  • 2020-12-02 04:02

    You can revert your

    rails g/generate controller/model/migration xxx
    

    output by using:

     rails d/destroy controller/model/migration xxx
    
    0 讨论(0)
  • 2020-12-02 04:06

    You can undo a rails generate in the following ways:

    • For the model: rails destroy MODEL
    • For the controller: rails destroy controller_name
    0 讨论(0)
  • 2020-12-02 04:08

    If you prefer to delete the controller manually:

    For controller welcome

    rm app/controllers/welcome_controller.rb
    rm app/views/welcome
    rm test/controllers/welcome_controller_test.rb
    rm app/helpers/welcome_helper.rb
    rm test/helpers/welcome_helper_test.rb
    rm app/assets/javascripts/welcome.js.coffee
    rm app/assets/stylesheets/welcome.css.scss
    
    0 讨论(0)
  • 2020-12-02 04:08

    Removed scaffolding for selected model:

    bin/rails d scaffold <AccessControl> //model name
    
    0 讨论(0)
提交回复
热议问题