Ruby-on-rails 在 Rails 中撤消脚手架
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/963420/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Undo scaffolding in Rails
提问by Daniel
Is there any way to 'undo' the effects of a scaffold command in Rails?
有什么办法可以“撤销”Rails 中脚手架命令的效果?
回答by Rishav Rastogi
First, if you have already run the migrations generated by the scaffoldcommand, you have to perform a rollback first.
首先,如果您已经运行了scaffold命令生成的迁移,则必须先执行回滚。
rake db:rollback
You can create scaffolding using:
您可以使用以下方法创建脚手架:
rails generate scaffold MyFoo
(or similar), and you can destroy/undoit using
(或类似),您可以使用销毁/撤消它
rails destroy scaffold MyFoo
That will delete all the files created by generate, but not any additional changes you may have made manually.
这将删除由 创建的所有文件generate,但不会删除您可能手动进行的任何其他更改。
回答by Misha Rabinovich
Rishav Rastogi is right, and with rails 3.0 or higher its:
Rishav Rastogi 是对的,使用 rails 3.0 或更高版本:
rails generate scaffold ...
rails destroy scaffold ...
回答by thekindofme
You can undo whatever you did with
你可以撤消你所做的一切
rails generate xxx
By
经过
rails destroy xxx
For example this applies generators to migration, scaffold, model...etc
例如,这将生成器应用于迁移、脚手架、模型等
回答by Sudhanshu Arya
If you just want to see the files a generator will create you can pass the generator --pretend or -p option.
如果您只想查看生成器将创建的文件,您可以传递生成器 --pretend 或 -p 选项。
回答by user917158
Best way is :
最好的方法是:
destroy rake db: rake db:rollback
For Scaffold:
对于脚手架:
rails destroy scaffold Name_of_script
回答by dedennufan
for first time, you can check you database migration if you have generate scaffold. you must destroy them to clean up your database
第一次,如果你有生成脚手架,你可以检查你的数据库迁移。你必须销毁它们来清理你的数据库
rake db:rollback
then
然后
rails d scaffold
回答by RageCore
rails d scaffold <scaffoldname>
Also, make sure you undo the migration you made either by rollback or to a particular version.
此外,请确保您撤消了通过回滚或到特定版本所做的迁移。
回答by uma
To generate scaffolding :
生成脚手架:
rails generate scaffold xyz
To revert scaffolding :
恢复脚手架:
rails destroy scaffold xyz
回答by starbuck
Rails destroy name
Rails 销毁名称
rake db:rollback
回答by Amit Suroliya
For generating scaffold in rails -
用于在导轨中生成脚手架 -
rails generate scaffold MODEL_GOES_HERE
For undo scaffold in rails -
对于在导轨中撤消脚手架 -
rails destroy scaffold MODEL_GOES_HERE

