Rails 不再喜欢这个了吗? “脚本/生成脚手架专辑” 适用于专辑型号

发布于 2024-07-19 09:21:11 字数 468 浏览 3 评论 0原文

script/generate scaffold Album

用于为名为 Album(Rails 2 之前)的模型生成脚手架。

现在(Rails 2 之后),您需要指定所有必填字段,这是正确的吗:

script/generate scaffold Album artist:String title:String

我一直在关注 Rails 1.1.6 的教程,并且很困惑为什么

script/generate scaffold Album

不能按照教程描述了,但我怀疑命令的新格式要求您明确拼写出脚手架中所需的所有字段。

如果 Rails 失去了仅根据模型名称简洁地生成脚手架的能力,这是令人失望的,因为它通过 schema.db“知道”模型的所有字段是什么,而无需您向脚手架命令显式声明它们。

script/generate scaffold Album

used to generate the scaffolding for a model called Album (pre-Rails 2).

Is it correct that these days (post-Rails 2), you need to specify all of the required fields:

script/generate scaffold Album artist:String title:String

I've been following along with a tutorial on Rails 1.1.6 and have been puzzled about why

script/generate scaffold Album

doesn't work the way the tutorial describes but my suspicion is that the new format of the command requires that you explicitly spell out all of the fields that you want in the scaffold.

It's disappointing if Rails has lost the ability to concisely generate scaffold based on the model name alone since it "knows" through schema.db what all of the fields for the model are without you explicitly declaring them to the scaffold command.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

辞慾 2024-07-26 09:21:11

如果您没有在命令中指定字段,Rails 将不会构建任何预先填充字段信息的脚手架,就像在视图中一样。

script/generate scaffold Album

应该仍然有效,但您必须制作所有表单和显示视图以及定义迁移文件中的所有字段。

If you don't specify the fields in the command then Rails won't build any of the scaffolding with the fields information pre-populated, like in the views.

script/generate scaffold Album

should still be valid, but you'll have to go make all the form and display views as well as define all the fields in the migration file.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文