Found a Bug in Rails 2.1... kinda
Posted on 20 August 2008 by Johannes Fahrenkrug. Tags: Ruby railsYesterday I've encountered some strange behavior in Rails 2.1. When I called build on an association that was empty (i.e. customer.orders.build) and then passed that association as a collection to a partial, nothing got displayed. When I called length or each {} on that association right after the call to build, however, it worked. So I sort of needed to "commit" the build call by calling length right after.
I posted it to the Ruby On Rails Core group and it turned out that it was indeed a bug. It had been fixed in edge already, though.
So if you're not using edge, but the actual Rails 2.1 release, make sure to call length (i.e. customer.orders.length) after you call build on an empty association until the fixed version gets released.
Comments
Please keep it clean, everybody. Comments with profanity will be deleted.
blog comments powered by Disqus