How do I reverse a 'rails generate'?

2019-01-09 20:47发布

i.e. delete all the files it created and roll back any changes made? Not necessarily to the db, but more to the config files.

E.g. automatically deleting all the resource mappings for the model/controller deleted in the routes.rb file and everywhere else that changes might have been made?

Thanks.

18条回答
仙女界的扛把子
2楼-- · 2019-01-09 21:21

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

查看更多
看我几分像从前
3楼-- · 2019-01-09 21:24

You can undo a rails generate in following ways:

  • For Model: rails destroy MODEL
  • For Controller : rails destroy controller_name
查看更多
神经病院院长
4楼-- · 2019-01-09 21:27

You can destroy all things that was created same way except little thing change. For controller,

rails d controller_name (d stands for destroy)

For Model

rails d model_name

you just put d(destroy) instead of g(generate) in your migration.

查看更多
Bombasti
5楼-- · 2019-01-09 21:28

All generations of rails have a destroy of them, so , if you create by generator a (for example) scaffold named "tasks", to destroy all the changes of that ganerate you will have to type:

rails destroy scaffold Tasks

Hope it helps you.

查看更多
看我几分像从前
6楼-- · 2019-01-09 21:29

Removed scaffolding for selected model

bin/rails d scaffold <AccessControl> //model name
查看更多
Evening l夕情丶
7楼-- · 2019-01-09 21:30
rails destroy controller lalala
rails destroy model yadayada
rails destroy scaffold hohoho

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

rails d controller lalala
rails d model yadayada
rails d scaffold hohoho
查看更多
登录 后发表回答