view my latest photos at flickr
ruby on rails diagram generator - RailRoad
April 11th, 2007I came across RailRoad today on another blog. Very cool idea. When I had done some work in the past, I found it hard to remember class names and method names. I’m used to a Java IDE like IDEA to do name completion, but that largely doesn’t exist for the Ruby world, or it may be available now. Generating diagrams from your code should help things a lot.
RailRoad is a diagram generator for Ruby on Rails applications. Actually, it’s a simple Ruby script that loads the application classes and analyzes its properties (attributes, methods) and relationships (inheritance, model associations like has_many, etc.) The output is a graph description in the DOT language, suitable to be handled with tools like Graphviz.
RailRoad can produce:
* Model diagrams, showing both inheritance hierarchy and models associations. You can choose to show the model “content columns” and its types.
* Controller diagrams, showing inheritance hierarchy. You can include the controllers’ methods, grouped by its visibility (public, protected, private.)

an example Model diagram
Ruby On Rails Active Record gotcha
May 11th, 2006I’ve been trying to do some Ruby On Rails development in my spare time for a personal fun project. I’ve been through almost every RoR tutorial, I’ve got the Agile Web Development with Rails book and read the majority of it, and written a very popular Ruby On Rails Cheatsheet. But every time I try to display relationship details between tables, I always got errors “undefined method“. I couldn’t see why this would work in my tutorials, but never in my own personal work. It all came down to a single letter - ’s’.
For example, if I had 2 tables; Notes and Comments with a One To Many relationship. Tables are as follows:
create table notes (
id int not null auto_increment,
body varchar(60) not null,
primary key (id)
);
create table comments (
id int not null auto_increment,
details varchar(40) not null,
note_id int not null,
primary key (id)
);
It wasn’t until I referred back to Amy Hoy’s ActiveRecord cheatsheet (Thanks Amy) that I finally found my problem. This is the one time where (my assumed) convention bit me in the ass instead of working for me. Looking back and “reading code as english” as you can commonly do with Ruby code, it makes sense.
class Note < ActiveRecord::Base
has_many :comments #note the pluralization
end
class Comment < ActiveRecord::Base
belongs_to :note #note the singular reference
end
I had previously thought the convention was that both has_many and belongs_to refered to a singular reference (comment & note). Not so. If you read the code “Comment belongs_to :note” and “Note has_many :comments” it makes perfect sense.
So in my view, I would try to reference fields like note.comment.details and get the error undefined method as the code was looking for the method note.comment instead of a related object. As soon as I fixed my model by adding the ’s’ to has_many, everything worked right away.
Newbie mistake I guess. I’m sure it won’t be the last.
just do something already
December 20th, 2005Along the lines of Joel’s Fire and Motion article, the guys at 37signals are on the right track:
If you find yourself talking more than walking, shut up, cut the vision in half, and launch it. You can always fill in the gaps later. In fact, you’ll know more about what gaps need to be filled after you’ve launched “half a feature” than if you tried to fill them in before launching anything.
Too much thinking can lead to analysis paralysis. Just start the ball rolling, get forward motion and momentum on your project. Obviously some degree of planning is required, but a customer won’t pay you for pages and pages of design documents and fancy flow diagrams. You get paid for a working product. Frequent iterations, tweaking along the way will get you where you need to go. Mind you, this applies well to web applications and smaller teams projects. I could never apply this to a larger project like at my work. The teams are much larger, the release cycles need to be longer and the product is much more complex. Planning is required, but we tend to keep it to a minimum where possible.
Rails gets official
December 15th, 2005
Rails 1.0: Party like it’s one oh oh!
Ruby on Rails goes 1.0 finally and even gets a 37signals visual overhaul. Upgrade now.
37signals
Ruby on Rails book review and cheatsheet
December 6th, 2005
Along with many software coders, I’ve become a Ruby on Rails fan as well. I’ve had an interest in it for a while after reading so many websites talking about productivity gains. Its simplicity and speed of getting an application moving amazed me. Now I want to give back by helping to increase the RoR knowledge base by providing a Ruby On Rails cheatsheet.
When coding in Java, I’d get an idea in my head, start brainstorming about how it would work then I’d start setting up my work environment at home.
- Create a new directory structure for the project.
- I’m going to need logging - get the latest log4j jars.
- Get JUnit for unit testing and include in project.
- Get Hibernate for database persistence. Configure the hibernate files.
- Get a templating project (Spring/Velocity/etc - take time to decide on which one) and add to project.
- Do I want to use Struts for this too?
- Assemble all the other jars I’ll need.
- Setup a new project and configuration in my IDE.
- Setup database connections and test that out.
- Etc, etc, etc.
By the time I even start to write one line of code, it’s usually taken me until 2 evenings later, as I’ve got a day job and these ideas are meant as fun nighttime projects. By this point, the excitement of the idea is lost and the project gets shelved along with the others as something more important has usually come along or interrupted me enough to get in my way.
With Ruby On Rails, it’s a much different story. Within 5 minutes of sitting at my computer, I can be up and running with a complete environment, database configuration and blank template pages already showing me some results. Hours vs minutes makes a lot of difference. Just getting the project started is much faster, not to mention the amount of code required to do comparable tasks.
After trying out mostly all of the tutorials available on the internet, I ordered “Agile Web Development with Rails” from Chapters (Canada’s version of Barnes & Noble). I dug in, skipping to the appendix to review the Ruby syntax chapter so I’d understand the Rails code better. The book is a very easy read, written like a teacher is talking to you. I find this much easier to follow along than a heavily technical book. The book walks you through a tutorial as though you’ve been hired to create a storefront application for your customer who you consult with frequently (the Agile part of the book). And the tutorial gives you just enough information to keep you working along, rather than overloading you with everything on that subject in the chapter. If you want further in-depth knowledge of a subject, that comes in the next section of the book after the tutorial is completed.
I flew through the tutorial reading while commuting back and forth from work, then typing up the code when I arrived home at night. I stopped after the tutorial section, but haven’t jumped into the more in-depth content yet. I think I may review that section as I get stuck and need more information on a specific topic.
For now, I’m happy to try building some simple applications I’ve had floating around in my head for a while. And it won’t take me 8 hours before I type a single line of code.
Don’t get me wrong, I still really like Java and I know I will still use it (my day job is all Java based). There’s certain things I would choose Java for over Ruby on Rails and vice-versa. Use the right tool for the job. And now I have an extra tool in my toolbox.
Also, as part of my Ruby on Rails learning process I took a lot of notes (I’m a visual learner), so writing notes helps me to remember better, along with retyping out all the code in detail. Inspired by the PDF cheatsheets Amy Hoy produced, I’ve created my own set of notes and general cheatsheet as a reference to keep next to my desk when I need to jog my brain.
The document is at 14 pages so far and I’ll probably update it as I continue to learn more on RoR.
Continue on to download the Ruby On Rails cheatsheet.



