Rails 中迁移的自动注释模型?
我似乎记得有一个插件或 Rake 片段可以在运行迁移后在各种模型类中添加注释? 当我想查看给定模型具有哪些字段时,必须查看 db/migrate/X 是一件苦差事。
如果没有的话,我当然会写一篇。 :)
I seem to recall that there was a plugin or Rake snippet that would put comments in various Model classes after running a migration? It's a chore to have to look at db/migrate/X when I want to see which fields a given model has.
If not, I'll write one, of course. :)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您可能正在考虑 Annotate Models 插件:
http://repo.pragprog.com/svn/Public/plugins/annotate_models/< /a>
我相信这正是你所描述的,尽管我已经有一段时间没有亲自使用它了,所以不能保证它在最新的 Rails 版本上的行为。
问候,
尼尔·S。
You may be thinking of the Annotate Models plugin at:
http://repo.pragprog.com/svn/Public/plugins/annotate_models/
I believe that does exactly what you describe, although I haven't personally used it in a while, so can't vouch for its behaviour on more recent Rails versions.
Regards,
NeilS.
有一个学派建议您不应在模型中添加属性注释,因为它违反了 DRY 原则。 我不会争论这一点。 然而,识别模型属性的一种真正好的方法是在 ./script/console 中简单地键入模型名称。
在开发 Rails 时,我总是打开 ./script/console 会话。
There is a school of thought that suggests you you shouldn't put attribute comments in the model as it breaks the principal of DRY. I won't argue the point. However, one real nice way of identifying attributes of the model is to simply type the Model name when you are in ./script/console
I always have ./script/console session open when developing Rails.
我维护 annotate gem (它最初是 Dave Thomas 的那个令人尊敬的插件),最新版本允许您运行
它会向您的项目添加一个 rake 文件。 之后,每当您运行 rake db:migrate 时都会执行 annotate(但仅限于开发模式)。
...目前此功能似乎已损坏 :-(
I maintain the annotate gem (which started life as that venerable plugin by Dave Thomas) and the latest version allows you to run
which adds a rake file to your project. Afterwards, annotate will be executed whenever you run
rake db:migrate
(but only in development mode)....currently this feature seems to be broken :-(