Read my latest article: Planet Argon Blog (posted Wed, 17 Feb 2010 15:11:00 GMT)

Aliasing resources in Ruby on Rails

Posted by Robby Russell Tue, 23 Jun 2009 06:00:00 GMT

6 comments Latest by ghd Wed, 10 Mar 2010 08:52:10 GMT

Earlier today, a friend working on a project asked me how we approached routes on our website. If you take a quick peak at our website, you’ll see that we have URLs like so:

When we launched our new site a few months ago, we were working off an existing code base. We have a model named, TeamMember and a corresponding controller. When we decided to come up with new conventions for our URL structure, we opted to ditch the normal Rails conventions and go our own route. What we weren’t sure about was how to alias resources in our routes nicely. After some digging around, we came across the :as option.

So, our route was:

  map.resources :team_members

Which provided us with:

  • /team_members
  • /team_members/robby-russell

We simply added :as => 'who-we-are' to our route:

  map.resources :team_members, :as => 'who-we-are'

...and we got exactly what we were looking for in our URLs.


* /who-we-are
* /who-we-are/gary-blessington

If you look at our site, you’ll notice that we did this in a few areas of our application so that we could define our own URL structure that was more friendly for visitors and search engines.

Anyhow, just a quick tip for those who want to change up their URLs with Ruby on Rails.

p.s., if you know where I can find this documented, let me know so that I can provide a URL in this post for others. :-)

Subscribe to my RSS feed Enjoying the content? Be sure to subscribe to my RSS feed.
Comments

Leave a response

  1. Avatar
    Chris Lloyd Tue, 23 Jun 2009 07:45:25 GMT

    Here are the docs

  2. Avatar
    Koen Van der Auwera Tue, 23 Jun 2009 07:45:26 GMT

    It’s documented over here in the part ‘options to customize the resulting routes’. ;)

  3. Avatar
    susan Wed, 10 Feb 2010 12:44:07 GMT

    . Unfortunately, wholesale ugg boots discoloration, or caused by another product protection vacuum Shoes UGG Australia in May, one year warranty. discount ugg boots The first step in maintenance is a wire brushUggs, suede or nubuck brush in one direction. If done regularly, this will prevent dirt or dust to settle from the fiber suede and reduce potential damage caused by debris in the air. But sooner or later, discount ugg cardy boots Uggs need cleaning or in certain areas or in general. Eraser quality stain can be used to reduce the stains before cleaning.

  4. Avatar
    gucci handbags Tue, 02 Mar 2010 01:47:08 GMT

    Thank you this article I hope you have an enjoyable day. gucci shoes gucci handbags gucci handbags gucci belts

  5. Avatar
    gucci belts Tue, 02 Mar 2010 02:10:58 GMT

    Thank you this article I hope you have an enjoyable day. chi flat iron chi hair straightener chi flat irons chi hair tools

  6. Avatar
    ghd Wed, 10 Mar 2010 08:52:10 GMT

Share your thoughts... (really...I want to hear them)

Comments