Ruby-on-rails 在 RoR 中回滚生成的控制器/模型

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/5284239/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-03 00:39:32  来源:igfitidea点击:

rollback generated controller/model in RoR

ruby-on-railsrubyscaffolding

提问by Itay Moav -Malimovka

I created, using the scaffolding, a model and controller files.
Later I discovered it would be a good idea to create the tables in the DB first...
My question, How can I role back the generated files and regenerate them now, that I have the tables in the DB?

我使用脚手架创建了一个模型和控制器文件。
后来我发现首先在数据库中创建表是个好主意......
我的问题是,我如何重新生成生成的文件并立即重新生成它们,我在数据库中有这些表?

I just started learning RoR, so right now I am not interested in best practices, just learning the tool box this FW (RoR) comes with.

我刚开始学习 RoR,所以现在我对最佳实践不感兴趣,只是学习这个 FW (RoR) 附带的工具箱。

And, do you have a recommendation for a good tutorial? I do know to use google, it is just that search engines don't know, yet (working on that), how to grade tutorials.
Edit:For my last question I found Learning Ruby on Rails

而且,你有什么好的教程推荐吗?我知道使用谷歌,只是搜索引擎不知道,但(正在努力),如何给教程评分。
编辑:对于我的最后一个问题,我发现了Learning Ruby on Rails

回答by stephenmurdoch

try

尝试

rails destroy scaffold XXXXX

one thing that I find puzzling though is that you said "Later I discovered it would be a good idea to create the tables in the DB first..."

我觉得令人费解的一件事是你说“后来我发现首先在数据库中创建表是个好主意......”

Well, rails creates a migrationfile for you when you run the generator in the first place, and this file will create your DB tables and fields when you run it using rake db:migrate

好吧,当您首先运行生成器时,rails 会为您创建一个迁移文件,当您使用该文件运行它时,该文件将创建您的数据库表和字段rake db:migrate

PS - here's a few good tutorials for you:

PS - 这里有一些很好的教程给你:

回答by ultrakain

You can rollback controller.

您可以回滚控制器。

rails destroy controller [controller]

回答by fengolly

You can delete all the files Rails created -- just look at the printout on your command line, see what files rails created, and delete them.

您可以删除 Rails 创建的所有文件——只需查看命令行上的打印输出,查看 rails 创建的文件,然后删除它们。

I don't know why you would want to create all the tables in the db, but that's fine, I guess. I prefer to let rails do it. Either way, Rails won't mind. You can always add / change fields using Rails, even if you created the tables outside Rails.

我不知道您为什么要在 db 中创建所有表,但我想这很好。我更喜欢让 Rails 来做。无论哪种方式,Rails 都不会介意。您始终可以使用 Rails 添加/更改字段,即使您在 Rails 之外创建了表。

Ryan Bates' Railscasts are excellent tutorials.

Ryan Bates 的 Railscasts 是很好的教程。