Rails 中迁移的自动注释模型?

发布于 2024-07-29 16:57:12 字数 122 浏览 2 评论 0原文

我似乎记得有一个插件或 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 技术交流群。

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

发布评论

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

评论(3

巡山小妖精 2024-08-05 16:57:12

您可能正在考虑 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.

初懵 2024-08-05 16:57:12

有一个学派建议您不应在模型中添加属性注释,因为它违反了 DRY 原则。 我不会争论这一点。 然而,识别模型属性的一种真正好的方法是在 ./script/console 中简单地键入模型名称。

 > User
=> User(id: integer, loginname: string, password: string, fullname: string, created_at: datetime, updated_at: datetime) 

在开发 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

 > User
=> User(id: integer, loginname: string, password: string, fullname: string, created_at: datetime, updated_at: datetime) 

I always have ./script/console session open when developing Rails.

2024-08-05 16:57:12

我维护 annotate gem (它最初是 Dave Thomas 的那个令人尊敬的插件),最新版本允许您运行

rails g annotate_models:install

它会向您的项目添加一个 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

rails g annotate_models:install

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 :-(

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