我使用脚手架创建了模型和控制器文件。
后来我发现首先在数据库中创建表是个好主意......
我的问题是,我如何恢复生成的文件并重新生成它们,因为我在数据库中有表?
我刚刚开始学习RoR,所以现在我对最佳实践不感兴趣,只是学习这个FW(RoR)附带的工具箱。
另外,您有好的教程推荐吗?我确实知道使用谷歌,只是搜索引擎还不知道(正在研究)如何对教程进行评分。
编辑:对于我的最后一个问题,我发现学习 Ruby on Rails
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.
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
发布评论
评论(3)
尝试
一件事,我觉得令人困惑的是,你说“后来我发现首先在数据库中创建表是个好主意......”
好吧,rails 创建了一个 当您首先运行生成器时为您提供迁移文件,当您使用
rake db:migrate<运行它时,该文件将创建您的数据库表和字段/code>
PS - 这里有一些不错的教程供您使用:
try
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 migration file 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
PS - here's a few good tutorials for you:
您可以回滚控制器。
You can rollback controller.
您可以删除 Rails 创建的所有文件——只需查看命令行上的打印输出,查看 Rails 创建了哪些文件,然后删除它们。
我不知道为什么您想要在数据库中创建所有表,但我想这很好。我更喜欢让 Rails 来做。不管怎样,Rails 都不会介意。您始终可以使用 Rails 添加/更改字段,即使您在 Rails 之外创建了表。
Ryan Bates 的 Railscasts 是很棒的教程。
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.
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.
Ryan Bates' Railscasts are excellent tutorials.