FancyRoutes: A Nicer DSL for Routes in Rails
FancyRoutes (or Github repo) is a new Rails plugin that provides a less crufty way to define routes, developed by TRED (a team of Australian Rubyists, including Chris Lloyd, Myles Byrne, Tim Lucas, Carl Woodward - amongst others).
FancyRoutes is just a layer over the usual routing (so hopefully compatibility should be maintained) and it has a pretty groovy syntax:
get / 'orders' >> :orders > :index with route / :slug / 'order' >> :orders do get > :show put > :update end get {'item_images' => :controller} / :image > :show
Support from: 1st Easy offers UK Rails hosting (dedicated and shared) on a Phusion Passenger (mod_rails) and LAMP stack. Want to evaluate performance or get to know us first? Let us set up a trial account for you - full technical support included!
March 9th, 2009 at 4:23 pm
I can't say I really like the Syntax. I dislike DSL's in general, really.. especially for trivial tasks as routing (who has ever written a routes.rb with over 100 lines?).
March 10th, 2009 at 9:02 am
absolutely ugly
March 10th, 2009 at 9:03 am
Perlish mess
March 10th, 2009 at 10:44 am
It looks pretty fancy. Good use of operator oveloading. But it seems another language, not ruby.
Sometimes, DSLs are so fancy it seems you're using a new language. I personally will continue using the actual rails routing system (which is very very well documented in railsguides.info).
March 11th, 2009 at 1:01 am
So this is ugly, but should_do_some_thing_or_other crap in RSpec, et al, is acceptable? Wonders will never cease :)
March 12th, 2009 at 4:23 pm
Beauty is in the eye of the beholder I guess. Nice little experiment, but way too clever. Less is more and all that.
March 12th, 2009 at 4:29 pm
For me it all comes down to whether something is memorable, rather than ugly or good looking. So, I probably would stick with the regular routing scheme since I find it pretty easy to remember and use (unlike almost every assertion in Test::Unit and the various crazy names in RSpec and Shoulda macro names).
March 13th, 2009 at 1:24 am
+1 on memorable. But I'll go one further: guessable. \
Plus I don't think the / operator to separate path segments is an improvement over ":controller/:action/:index"
March 13th, 2009 at 1:37 am
Nice one, Christian. Good point!
I agree. That's why I would probably stick to regular routing. I think of URLs as strings, so I quite like to see them in that way in a formal/logical setting too.
I think it was Chris Wanstrath or PJ Hyett who said on Twitter some time ago that if you're coding something and you consistently get the syntax or keywords wrong, you should try and actually change the underlying syntax or keywords to meet your assumptions. Powerful idea. With that as a benchmark, I'd probably make few changes to routing.
March 13th, 2009 at 11:47 am
Hmmm... certainly an interesting concept.
On a slight tangent there is an good run down of how different web frameworks do routing at http://labs.kraih.com/blog/2008/10/dispatchers-for-dummies.html
/I3az/