Auto Center and Zoom with YM4R

When I blogged last month about abstracting mapping with YM4R I commented: What I’ve not yet discovered (and may not be implemented) is a way to automatically center and zoom a map. It would be very nice to be able to add a batch of points to a map and have the plugin automatically work out their mid-point. Maybe I need to work on that a little… What I was missing was the center_zoom_on_bounds_init method. There are various ways to interact with it, but I’ve chosen: ...

Corrected bus routes on Rails

In the process of building my bus route app, I realised that half the data for bus stops is missing. While the site’s developers have done a good job of providing clear data on half the stops, if you want to see stops going in the other direction, you have to use a drop-down box that triggers an AJAX request and repopulates the table. A little digging shows that the call is to: ...

Bus routes on Rails

Following on from my previous entry about scraping bus route data from The Rapid’s website, and to begin to demonstrate the possibilities it opens up, I’ve set up a simple web service to provide route and stop data. It’s based on the new REST style from Edge Rails, and routes are scoped by city to allow for future expansion. To get data on Route 1, GET: http://projects.jystewart.net/buses/cities/1/routes/1 To get a list of the stops within 1.5 miles of a given longitude and latitude, GET: ...

Scraping Grand Rapids bus routes

The Rapid, the bus service for Grand Rapids and surrounding areas, recently redesigned their website. The redesign was long overdue and the result certainly looks a lot cleaner, if still far from inspiring. They’ve added a flash-based map showing their routes (though it could do with being a little larger on the page) and added PDF maps of each route (eg. this one for Route 6)). Unfortunately as yet there’s no tool for working out routes, but that’s not a big surprise. ...

Rails flash tests deprecated?

After returning from a weekend away, updating my apps to the latest Edge Rails, and running my test suite I started spotting new deprecation warnings: DEPRECATION WARNING: assert_flash_exists is deprecated and will be removed from Rails 2.0 DEPRECATION WARNING: assert_flash_has is deprecated and will be removed from Rails 2.0 Kevin Clark has posted on the deprecation of assert_tag in favour of assert_select, but I’ve yet to see any notes on this one. Looking in the actionpack CHANGELOG there’s no reference to the change, and there’s no documentation in the new home of those methods (actionpack/lib/actioncontroller/assertions/deprecated_assertions.rb) to suggest what we should use instead other perhaps than making use of the code used in those methods. eg: ...

Abstracting mapping with YM4R

When Grand Rapids WiFi–then a PHP application–first implemented google map support all the logic for producing those maps came in the templates. The controller passed the view a list of locations for that page, and it wrote out a series of javascript calls that produced the map. It was a little unreliable and very clunky, but it worked. When I moved the app over to rails, that was one aspect that I didn’t change, and it continued to work. ...

Namespaces, attributes and content in rxml

Rails’ RXML templates (powered by Builder) are a great way to generate various different types of XML output from your application, but the documentation could be lacking. I’ve been working with namespaced content for a while but I’ve spent quite a while today trying to work out how to add an element in an explicit namespace, with attributes and text content. To create an ‘id’ element is straightforward: xml.id 'my-id-here' and then to put that tag in the ‘foo’ namespace you need: ...

Rails' Improved Join Model Creation

Jeremy Kemper has just checked in a change to Edge Rails that fixes my biggest frustration with has_many :through. Since it’s appearance a couple of versions back, has_many :through has been a great addition to the rails associations toolkit, making the use of join models infinitely cleaner. But until recently it was rather cumbersome to create those relationships. For example, if I wanted to add an author to a book where the relationship is defined as: ...

loads_from_amazon (Ruby on Rails plugin)

UPDATE (10/2008): This plugin is no longer maintained. I’d recommend looking at one of the newer alternatives such as acts_as_amazon_product if you need this functionality. I’ve been procrastinating on getting my first Ruby on Rails plugin (first anyone else might be interested in, at least) out the door, mainly due to some configuration problems with Subversion, but finally I have that all sorted out and the plugin ready to go. loads_from_amazon is an ActiveRecord Mixin that works with the Ruby/Amazon library to let you populate an ActiveRecord object with the details of a product listed on amazon. In the README I use the following example: ...

Grand Rapids WiFi on Rails

Grand Rapids WiFi relaunched today with a change under the hood to Ruby Rails. The site has been through several iterations since I took it over in September 2004. It often functions as my testbed for new features I’d like to trial, and since most of my custom development is now rails-based, it made sense to make the switch. Feature-wise, not much has changed. A few URLs have changed slightly (with appropriate redirects provided by rails and lighttpd), there’s some caching in place, and there are a few new “ajax” effects, but otherwise it’s so far a straight port. And on the UI side the changes are also minimal. The use of microformats has increased somewhat, but the long promised redesign will have to wait a little longer. ...