Using Railroad with Rails 2.3
Railroad is a great tool to to help document your Rails projects. It automatically creates class diagrams for Model relationships and Controller relationships in DOT format. With Graphviz installed, you can automatically generate nice looking SVG or PNG diagrams. Even better, Roy Wright has improved the original to work with both Rails and Merb projects. However, when I tried to use Railroad with a Rails 2.3 project, it suddenly couldn’t find my controller files:
railroad -C | neato -Tpng > controllers.png Error loading controller classes. (Are you running railroad on the application's root directory?) /ruby/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:31: in `gem_original_require': no such file to load -- app/controllers/application.rb (MissingSourceFile)
After looking into rubygems custom_require and a number of other things, I finally noticed that Railroad was trying to load application.rb rather than application_controller.rb. Yes, application.rb has a new name in Rails 2.3, and anything that depends on the old name will need to be updated when you move up from any earlier version of Rails. In this case I made a quick and dirty fix in the Railroad gem:
rails_framework.rb: line 20
# get the controller's files returning the application controller first in returned array def get_controller_files(options) files =  files << 'app/controllers/application_controller.rb' # was application.rb files += Dir.glob("app/controllers/**/*_controller.rb") - options.exclude files.uniq end
If you are on an older version of the gem, you will need to change it here instead:
controllers_diagram.rb: line 39
require "app/controllers/application_controller.rb" # was application.rb
The real fix of course is to check the Rails version, and proceed accordingly. Meanwhile, I’m happy to have realized why application.rb was not being found.
Roy Wright updated his project, linked above, to work with Rails 2.3 within a day of this post (as he notes in the comments below. Thanks Roy!) The tips here may still be useful to you if for any reason you are still using an older version.