Saturday, May 12, 2007

Visualize Models 1.1

Visualize Models is a small rake script that will generate .png images for Ruby On Rails models (i.e. the database tables) that will display the table/column information. The associations between tables is based on the default Ruby On Rails naming convention (i.e. <table>_id columns). See image below for the typo blog models:

Install as a plugin. From your rails application root, run
ruby script/plugin install svn://rubyforge.org//var/svn/visualizemodels/visualize_models
Run the plugin with:
rake visualize_models
This plugin depends on GraphViz, which you can find here.

If you're a Mac user, the Darwin port of GraphViz seems to work better. Just do:

 sudo port install graphviz

This program has its roots in the Annotate Models by Dave Thomas. See also the RubyForge project page for additional info.

In addition to Visualize Models there are two (that I'm aware of) other projects that you can use to visualize the database in Ruby On Rails:

If you know about any additional resources to visualize rails models, please drop me a mail at nils@<this domain>.

Update: Fixed the ActiveSupport::Inflector in SVN now as noted in the comments. Visualize_models works out of the box for rails 2.2.2 and later now

9 comments:

  1. I have have installed grapviz on my windows XP and Visualize Models. But when I do rake visualize_models, it looked at all my tables but "failed to execute the 'neato' command"

    ReplyDelete
  2. Make sure that neato and dot is in your path and that you can start them from the command prompt.

    ReplyDelete
  3. Cheers for this plugin. It's been very useful

    ReplyDelete
  4. First, thanks for the plugin! After installation, I ran into a problem that Visualize::Inflector was not found. This was easily resolved by using ActiveSupport::Inflector in visualize_models.rb.

    ReplyDelete
  5. I'm a newbie on RoR and I get the message error 'Visualize::Inflector was not found' and I don't understand David medinets comment on how to address that. I can't find any reference to 'Inflector' in the .rb file.
    I run on Mac OSX and the command "sudo port install graphviz" doesn't work either..

    ReplyDelete
  6. ‘Visualize::Inflector was not found’ - it appears with the rails = 2.2.2, switch to 2.1 to generate your models if you are in hurry

    ReplyDelete
  7. Is there a way to pass parameters with this class. I would like to do some of the tables in the model. Current it does ever table.

    ReplyDelete
  8. sacredceltic: look in the visualize_models.rb file, and replace every "Inflector" with "ActiveSupport::Inflector". That should fix your error.

    ReplyDelete
  9. Hi Nils,
    nice program ;-))
    Is there a way to keep the GraphViz dot file ?
    I like to add some additional information into it before creating the png image.

    ReplyDelete