Book Review: Pro ActiveRecord

Right at the start of Pro Active Record the authors address a possible problem some may have with it: that there’s not enough in Active Record to warrant a full book. They point out that the basics are well covered as sections elsewhere but that this is the first book to really dig into working with legacy schema and other ‘advanced’ uses. That’s fair enough, but after reading the book I am still left with the question of why, then, they dedicate the first half to covering ActiveRecord’s most basic concepts? ...

Rails Geo Plugins: GeoX

GeoX is the latest kid on the Ruby on Rails geocoding block. The plugin was announced a couple of weeks ago and I’ve been meaning to explore it ever since, just in case it had any new features and also so that I can add it to my comparison chart. The feature set of GeoX is fairly straightforward. It supports a number of geocoding back ends: obviously google and yahoo are covered, but also mapquest’s relatively recent API. The standard lookup process is much like that provided by several other plugins—the sample given is: ...

New look for Sarah Masen's site

Thanks to some hard design work on the part of Rob Vander Giessen-Reitsma I was able to launch a new look for the website of singer/songwriter Sarah Masen a week or so ago. Sarah’s recently released three new EPs (her first releases since 2001, and all with hand made packaging) and it was high time the site got a new lease of life. At heart, the site is a simple rails application, and we’re still making frequent updates as we let the new design settle in and begin to hook the site together with the new web world that has sprung up since it was last given any real attention. One of the latest changes is the use of the flickraw gem to pull in photos from gigs. We’re using last.fm’s machine tags to identify events, which may not be the best route as we build out the archive but for now provides a nice way to disambiguate events on flickr, with the fringe benefit that the photos show up on last.fm too. ...

Site Launch: Georgia Music Store

One of the numerous side projects that’s been keeping me from blogging (alongside working full time and preparing for a round-the-world trip and an international move) made a quiet launch yesterday. You can find it over at shop.georgiamusicstore.com. The site is a component of a wider online presence for the Georgia Music Hall of Fame, providing e-commerce facilities for their gift shop. It went through numerous iterations as they refined how they wanted to manage stock, and now takes stock updates uploaded from CSV files for easy integration with their other back-office systems. Payments are handled through the excellent Active Merchant which makes the payment side of e-commerce development a breeze. Search come from ferret, and a little reassurance is provided by the wonderful exception_notification. ...

Trapping errors in partials without bringing down the page

Within a large project that uses a lot of partials to load in page components, there are a lot of potential points of failure. Add in a developer new to the project, or a front-end developer pressed into service working directly on your views, and the chances of someone editing a partial without realising it’s used in several more places than they’d noticed are fairly high. And if the partial hits an error, the exception will roll all the way up the chain and the end-user will see your 500 page. ...

Making Time#to_date public in Ruby 1.8.6

I just got caught out by an upgrade to Ruby 1.8.6 and an app which I can’t as yet upgrade to Rails 1.2.3. Ruby 1.8.6 (and 1.9) make the Time#to_date and Time#to_datetime methods private so any code which depends on those methods being public will break. The fix is very easy. I just copied the code from the relevant rails changeset and placed it in my environment.rb file: class Time %w(to_date to_datetime).each do |method| public method if private_instance_methods.include?(method) end end Of course, the ideal is to upgrade to 1.2.3, but that’s not on the cards just yet for this particular project. In the meantime, having to add five lines isn’t too much trouble. ...

The Joy of Separation

The thing I probably enjoy most about working with Rails is that it makes it easier to put logic in the right place than not to. To get back in the swing of blogging after a light couple of weeks, I thought it might be useful to run through an example of how that’s worked out for me recently. From time to time I’ve been working on an application that will contain a database of musicians. To be able to add new musicians quickly I’ve been using: ...

Graticule and acts_as_geocodable updates

Graticule and acts_as_geocodable, which I wrote about here, has a new release with a couple of updates worthy of note. First up is the addition of new geocoders which provide better coverage of locations outside North America, and second is IP address to co-ordinates conversion similar to that in GeoKit. Brandon has the lowdown, and I’ve updated the Comparison chart on the wiki.

:select and :include in ActiveRecord queries

Along with Bill Eisenhauer, I’ve been digging into what it would take to fix the problem I found with GeoKit, that it wouldn’t support :include queries properly. The explanation has seen us going deep into the internals of ActiveRecord to discover, as others have before, that the :select parameter (which GeoKit uses to build its distance column in the query) and the :include parameter don’t play nicely together. The reason for that is that Rails employs special methods to build the select parameters when there’s a :include in the query (ie. when you’re joining with other tables and eager-loading them) and currently ignores :select along the way. GeoKit would ordinarily produce SQL along the lines of: ...

Improvements to Rails' JSON Support

I’m travelling at the moment, so posting has slowed down after three weeks of daily updates. Nevertheless I’ve just about managed to keep up with my newsreader and was pleased to see that some attention has been going into the JSON support in ActiveResource. Previously parsing JSON that couldn’t be easily handled by the YAML parser was a bit of a pain. Now it’s simply a case of calling: ActiveSupport::JSON.decode(json_string) And the JSON param_parser I referenced in my “Versatile RESTful APIs Beyond XML” article no longer needs extra help. It’s simply: ...