Entries from November 2007 ↓

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!

Autotest crashes using RedGreen

At the time of this posting, the latest gem release of RedGreen has a bug. For those of you who don’t know, RedGreen is a handy tool to make specs/unit tests color according to the result of the test to make your testing output much easier to read. Unfortunately, at the time of this posting, the latest gems (Autotest, RedGreen, Ruby on Rails, RSpec) have an issue trying to play nicely together.

RedGreen actually will cause Autotest to crash when one of the following happens

  • You save your code with a compile error (eg. missing ‘end’ tag)
  • You add new spec files

The error looks like this:

/Library/Ruby/Gems/1.8/gems/ZenTest-3.6.1/lib/autotest/redgreen.rb:8: undefined method `match' for nil:NilClass (NoMethodError)

and will follow the compile error from your code, then stop autotest.

I posted a comment for the original author, Pat Eyler, and the comment was manually approved, but I haven’t received any actual response to know whether or not it will be updated. Just in case it won’t be, I hope this simple fix is useful for you.

To fix this problem, open up your

/Library/Ruby/Gems/1.8/gems/ZenTest-3.6.1/lib/autotest/redgreen.rb

file and change line 8 from:

if at.results.last.match(/^.* (\d+) failures, (\d+) errors$/)

to

if at.results.last && at.results.last.match(/^.* (\d+) failures, (\d+) errors$/)

Very simple, and it does the trick!

Partnership of the Century!

What happens when two of the brightest minds in technology join forces? You witness the most spectacular technological achievements mankind has ever known!

Reputable sources have already confirmed this event!! John Ford at Aldenta has the story.

So I’m an optimist.

In more down-to-earth news, my brother, John Ford (Aldenta), has partnered up with Glenn Fu for some pretty exciting projects. While I’m not at liberty to share the fact that we’re creating an actual DEATH STAR in order to TAKE OVER THE UNIVERSE, just know we’re having a great time and I’m learning a ton.

We start our days bright any early with a great workout (stretching, weights, running), smoothies for breakfast, and a healthy dose of international (and sometimes local) news to keep our minds from getting too trapped inside the little boxes where we spend so much of our time. After that John does things to make money while I fool around and try to learn stuff. Hopefully in the near (very near) future I’ll be doing more of what he’s doing. Right now it looks like we’re on the right track!

Additionally, since I’m currently in a very low-budget situation, we have the opportunity to try to take on some more exciting (and thus more risky) projects that neither one of us would have been able to attempt alone. I can’t wait to be able to share stories of our accomplishments! Until then, I have quite a bit of learning to do in order to get up to speed. Wish me luck!

Welcome to Glenn Fu!

Welcome everyone to Glenn Fu.  As a Java Developer I’ve managed to express my creativity through the development of games, applications, and artificial intelligence.  While I have managed to share some small parts of it through projects of mine such as GameLizard, I’ve never really been able to share all of my creations with more than my immediate peers.

Now that I’m transitioning into the web-based domain through languages such as PHP and Ruby (through the Ruby on Rails framework), I plan to keep up my usual innovative trend but this time with a much stronger focus on giving back to a community that has already given so much to me!  Hardly 2 weeks into learning Ruby on Rails I’ve already been given amazing assistance from the energetic online community that exists around it.

Inspired by their generosity, I plan to do my part to become an active contributor to this rich online community of creative and intelligent minds.  Hopefully it won’t take long before Glenn Fu becomes a great host of knowledge itself!