New to Rails 3? Check out the Ruby on Rails 3 Tutorial book and screencast.

A book and screencast series showing you how to develop and deploy industrial-strength Rails apps in a direct, step by step way. The screencast series includes 12 lessons over more than 15 hours! Get the best "over the shoulder" experience of following what a top Rails 3 developer does when building an app today. Click here to learn more.

FancyRoutes: A Nicer DSL for Routes in Rails

In Plugins

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!

Post to Twitter Tweet This Post

Vaguely Related Posts (Usually)

10 Comment Responses to “FancyRoutes: A Nicer DSL for Routes in Rails”

  1. #1
    Martijn Says:

    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?).

  2. #2
    mark Says:

    absolutely ugly

  3. #3
    Evan Says:

    Perlish mess

  4. #4
    Markus Says:

    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).

  5. #5
    Peter Cooper Says:

    So this is ugly, but should_do_some_thing_or_other crap in RSpec, et al, is acceptable? Wonders will never cease :)

  6. #6
    Christian Says:

    Beauty is in the eye of the beholder I guess. Nice little experiment, but way too clever. Less is more and all that.

  7. #7
    Peter Cooper Says:

    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).

  8. #8
    Christian Says:

    +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"

  9. #9
    Peter Cooper Says:

    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.

  10. #10
    draegtun Says:

    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/

Leave a Reply