Thursday, February 10, 2011

Useful Rails Stuff

While messing around with Rails, I found it very difficult to keep track of my nascent model because the information is so widely dispersed. The table information is in the migration files. The association information is defined by the model files. And all sorts of naming conventions have to be remembered.

So, I got to thinking: Maybe there is a tool which can digest a Rails application and generate an ER diagram.

Guess what? We are in luck. A quick google of 'rails er diagram' discovered Rails ERD. The installation is quite easy. Drop a few lines in your Gemfile and run bundle install.

Once installed, I run the tool as such:

rake erd filetype=dot attributes=foreign_key,inheritance,content inheritance=true

in my application directory. The output of the above command is a file named ERD.dot.

You can then convert the ERD.dot file into a png file with a tool provided by Graphviz (You can grab Windows installer at \\csfile\software\graphviz). Once installed, you get the dot command which can be used as follows:

dot -Tpng ERD.dot > yourmodel.png

You can view the png file in any browser.

Here is what I have so far:

Which you really can't see too well, so I will post a copy to Blackboard under Course Materials.

No comments:

Post a Comment