This post originated from an RSS feed registered with Ruby Buzz
by rwdaigle.
Original Post: What's New in Edge Rails: Nested Resource RESTful URL Builder
Feed Title: Ryan's Scraps
Feed URL: http://feeds.feedburner.com/RyansScraps
Feed Description: Ryan Daigle's various technically inclined rants along w/ the "What's new in Edge Rails" series.
This automatically builds a category_url(category) and category_article_url(category, article) helper (among others) that will build the appropriate URLs:
All right, that’s great. But why should we have to spell out these lengthy helper method calls when it’s clear that the first argument is a Category and the second is an Article? Can’t the appropriate helper method be implied by the types of these arguments? Yes – they can, and now they are with the new url_for update. Now you can pass in a collection of models to url_for, in order of nesting (root to child), and get the correct URL:
You can always fall back to the named routes provided for you by RESTful routing, but you now have an option to build URLs with an implied resource nesting.