|
This post originated from an RSS feed registered with Ruby Buzz
by rwdaigle.
|
Original Post: What's New in Edge Rails: Shallow Routes
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.
|
Latest Ruby Buzz Posts
Latest Ruby Buzz Posts by rwdaigle
Latest Posts From Ryan's Scraps
|
|
Rails’ routing mechanism is pretty slick. In a very intuitive way you’re able to describe the resources you want exposed at the URL level with this routing-DSL:
1
2
3
4
5
|
map.resources :users do |user|
user.resources :articles do |article|
article.resourcs :comments
end
end |
However, while this configuration makes articles available at /users/1/articles and comments at /users/1/articles/1/comments there are often times when you want to bypass the full nested hierarchy and directly access the resource in question. Now, with the shallow route option, you can.
1
2
3
4
5
|
map.resources :users, :shallpow => true do |user|
user.resources :articles do |article|
article.resourcs :comments
end
end |
This configuration keeps all the normal nested routes and give you direct routes as well:
1
2
3
|
articles_path #=> '/articles'
comments_path #=> '/comments'
article_comments_path(@article) #=> '/articles/1/comments' |
No longer do you need to separately declare direct routes in addition to nested routes, the :shallow option automatically make all necessary routes.
tags: ruby,
rubyonrails


Read: What's New in Edge Rails: Shallow Routes