Home Notes Web development Springsiteam.com site details

Springsiteam.com site details E-mail
Sunday, 27 February 2011 17:57

It's difficult to showcase the smaller details that aren't readily visible on a website, so I wanted to outline some of the finer points of the latest Rails project I've worked on, Springsiteam.com.  The details I want to point out focus on coding and server-side efficiency.

API key

The IDX feed requires an auto-generated API key to consume.  The easy thing to do would be to get a new key with every request sent to the server, but the efficient thing to do would be to send the request, and only if an unsuccessful response is received back, request a new API key, which is how I did it using Rails' in-built error- and exception-handling.


Springsiteam.com pagination


The IDX feed the site retrieves the property listings from features server-side pagination.  Since I use will_paginate for pagination in all my Rails projects, the best solution would be to use will_paginate to navigate the server-side pagination, which is what I did with the following simple code:

@listings = WillPaginate::Collection.create(page, 10, @count) do |pager|

Previous/Next navigation



The previous/next navigation on individual listing pages was a challenge, because thanks to the server-side pagination, only ten entries were retrieved at a time.  It was easy enough to link to previous/next listings when they weren't the first or last of those 10 records, but for those edge cases something else had to be done.  It would have been inefficient to send a new request to the server with every listing displayed, to get the adjacent listings, so what I ended up doing was:

  • Link to the adjacent listings as long as the current listing wasn't an edge case
  • If the current entry is the first on the page and the current page is not the first page, request the previous ten records from the server and link to the last of those records
  • Similarly, if the current entry is the last entry on the page and the current page is not the last page, request the next ten records from the server and link to the first of those records

Considering that most users don't navigate using previous/next buttons for more than a few entries, this saves a lot of unnecessary communication (traffic) between client and server.