Upgrading Restful Routes for Ruby on Rails 2.0

Yesterday I upgraded my project from 1.2.5 to RC1 of Ruby on Rails 2.0 and had some problems with my routes. During my upgrade process I found a really great post over at assert_buggy called How to upgrade Ruby on Rails Restful routes to 2.0.

Here you’ll find a really handy tool for checking everywhere in your code that you use any paths and allows you to fairly quickly create a hash linking from your old routes to the new correct routes, then run a script to update all of your code with the changes.

Unfortunately for me I had a LOT of custom routes, but I knew a lot of them still worked so I didn’t want to manually try and compare them with the “rake routes” output to see what was out of date.

At the time of this posting the code doesn’t have a way to show me only what’s messed up, and while I know the developer could add some functionality to check which of my routes was not found in a proper way, in the meantime I’ve come up with a cheap hack.

Just change line 22 from:

"#{m}" => ""

to

"#{m}" => "#{m}"

EDIT: The original author implemented my change and now requires no editing in order to use in this manner. Enjoy!

and do steps 3 and 6 which would be:

require 'route_migrator'
RouteMigrator.dump_current_route_methods
RouteMigrator.check_new_routes

and voila you’ll get some helpful output looking something like mine:

"The following new named routes you've specified seem to be not existent"
"home_room_path"
"partitioned_path"
"test_room_report_path"

Now instead of checking all 50+ of my crazy custom routes to figure out which ones don’t go anywhere, I’m given only the 3 from my code that don’t have a proper map.

My sincere thanks go out to assert_buggy!