---
title: "把表结构写进model（annotate_models，annotate）"
author: "RunUpwind"
date: "2011-06-29T14:02:50Z"
tags: []
categories: ["编程语言"]
slug: "model-annotate-models-annotate"
draft: false
lastmod: "2011-06-29T14:10:41Z"
id: 1109351
url: "https://runupwind.iteye.com/blog/1109351"
---

在做ROR开发时，经常要去查schema.rb, 确实有些不便。

 

《Web开发敏捷之道-应用Rails进行敏捷Web开发-第三版》中提到一个插件可将数据库信息添加到model顶端：annotate\_models。

 

因为书中所讲内容已是过去时了，已经找不到那个plugn了。

 

google得知：现在有这样的GEM了：

https://github.com/sagework/annotate\_models

 

首先安装这个GEM:

```
gem install annotate
```

 

然后在Gemfile里添加（重要）：

```
gem 'annotate'
```

 

到你的ROR app目录下，执行：

```
annotate
```

搞定。默认它会把 数据库表结构注释到 model文件的底部。