Archive for October, 2008

Completely custom routes

Thursday, October 30th, 2008

In a recent project for the New Zealand business community, we were required to have some really custom routes. An example of such routes would be geographical routes, e.g. /china, or /china/beijing.

We could try something like this:

map.country ':country', :controller => :locations, :action => :show,
  :country => Regexp.new(Country.all.map(&:name).join('|'))
map.region ':country/:region', :controller => :locations, :action => :show,
  :country => Regexp.new(Country.all.each{|c| "^#{c.name}" }.join('|'))

However we get this error “Regexp anchor characters are not allowed in routing requirements”. So we can’t use requirements. However, we can use route conditions instead. With inspiration from Jamis Buck’s route monkeypatch :

# /lib/routing_extensions.rb
module ThongKuah
module Routing

  module RouteExtensions
    def self.included(base)
      base.alias_method_chain :recognition_conditions, :path_regexp
    end

    # allows recognition for paths only matching the given regexp (conditions[:path])
    # allows recognition for paths not matching the given regexp (conditions[:not_path])
    def recognition_conditions_with_path_regexp
      result = recognition_conditions_without_path_regexp
      result << "conditions[:path] =~ path" if conditions[:path]
      result << "(conditions[:not_path]=~path).nil?" if conditions[:not_path]
      result
    end
  end

end
end

# /config.environment.rb
require 'route_extension'
ActionController::Routing::Route.send :include, ThongKuah::Routing::RouteExtensions

So now we can go :

map.country ':country', :controller => :locations, :action => :show,
  :conditions => {:path => Regexp.new(Country.all.map(&:name).join('|'))}
map.region ':country/:region', :controller => :locations, :action => :show,
  :conditions => {:path => Regexp.new(Country.all.each{|c| "^#{c.name}" }.join('|')) }

Note we can have negative matches as well. I’m sure the Regular expressions gods can do a negative match use Regexp only, but hey.

We found this rails idiom to be quite useful as this allows us full customisation of routing, if we need it. We have used it successfully for Made from New Zealand, so you check it out on pages such as www.madefromnewzealand.com/new-zealand and www.madefromnewzealand.com/new-zealand/auckland.

Pastie of the code here.

Happy Birthday ZoomIn – 3 today

Wednesday, October 29th, 2008



ZoomIn is 3 years today ! October 29th in 2005, ZoomIn was launched to the world. Currently we have 78734 places and 11558 users on ZoomIn ! Thanks to everyone who has contributed to ZoomIn.

ZoomIn has come a long way since that date, here’s a look at some the changes that have happened over the last 3 years.






Made from New Zealand is launching soon

Sunday, October 19th, 2008

The ProjectX team have been busy bees… We’ve been working on the Made from New Zealand project. Its launching soon…

Want to know more ??? Be watching NZ TV any channel at 8:20pm – all will be revealed.

We’re helping take New Zealand to the World!

Webpage test now in New Zealand

Tuesday, October 14th, 2008

The RPO team have released the AOL Webpagetest for New Zealand. Finally, we have a local content test frame work for testing the speed of a page.

Webpage Test is Awesome as it creates pageload waterfalls and average load times over a number of test iterations.


No there is no excuse for slow pages. Get to work NZ, we have a lot of internet to speed up !

Xlinks Digest – 06 / 10 / 2008

Monday, October 6th, 2008

Xlinks is a collection of interesting links as discovered by the ProjectX team.

    Warren Buffett to invest 3B in GE
    Added on 10/06/2008 at 02:11PM

    Using memcache to address more than 4Gb
    Added on 10/06/2008 at 02:10PM

    Stephen Fry on Cloud computing
    Added on 10/06/2008 at 02:09PM

    Mark Cuban – How to get Rich
    Added on 10/06/2008 at 02:08PM

    45 Rules for Creating a Great Logo Design: Hat tip to James from Bandit Design
    Added on 10/06/2008 at 01:57PM




    Added on 10/05/2008 at 07:21PM

    Earth Atlas – Google Earth data visualiser
    Added on 10/04/2008 at 10:07AM

    25 ways to be more productive as a designer
    Added on 10/02/2008 at 10:30PM

    YUI release 2.6.0
    Added on 10/02/2008 at 10:17PM