脚手架不更新视图
我对以下过程有疑问:
- 脚本/生成脚手架产品 title:string description:text
- db:migrate
然后我生成一个迁移,将列描述添加到
表产品并迁移数据库 再次。
我的问题是:为什么字段描述没有添加到项目视图中?这是正常的铁轨脚手架行为吗? 我想我在视频教程中看到脚手架也会更新视图,这会非常方便。 预先感谢您的任何帮助!
I have a question to the following procedure:
- script/generate scaffold product
title:string description:text - db:migrate
then I generate a migration which adds a column description to the
table products and migrate the db
again.
My question is: why is the field description not added to the project-views? Is that normal rails scaffold behaviour?
I think I saw in a video tutorial that the scaffold updates as well the views, which would be very convenient.
Thanks in advance for any help!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
这是正常的,因为脚手架不会“监视”表或任何其他脚手架相关资源(控制器、模型、视图、测试等)的更改。
在生成脚手架时,您已经有了描述列。为什么您需要为此进行另一次迁移?
This is normal since scaffold does not "monitor" changes to the table or to any other scaffold-related resource (controller, model, views, tests, etc.).
You have description column already when generating the scaffold. Why do you need another migration for this?
这是脚手架的正常行为,但是还有其他选择。
如果您要查看 Ryan Bates nifty_scaffold 生成器,那么这将允许您重新运行支架一代。 假设您没有更改生成的代码。
这些生成器可以根据数据库模型的当前状态重新生成视图/规范/测试。
请注意,如果您已经自己自定义了视图,那么它们可能会被覆盖。
This is normal behaviour for scaffolding, however there are alternatives.
If you were to look at Ryan Bates nifty_scaffold generator then this would allow you to re-run the scaffold generation. Assuming that you hadn't changed the generated code.
These generators can regenerate the views/spec/tests based upon the current state of the database model.
Be aware that if you have already customised the views yourself then they could be overwritten.