Plugins - Sexy Nested Resources
Add to favoritesSexy Nested Resources
Determination of parent resources
This plugin adds the ability to determine the parent resource types. AbstractRequest, ActionController and ActionView all have a method called parent_resource_types().
Given this routing table:
map.resources :changes
map.resources :products do |products|
products.resources :releases do |releases|
releases.resources :changes
end
end
parent_resource_types() will return [:product, :release] for /products/:product_id/releases/:release_id/changes and [] for /changes
Sexy Context Sensitive url_helpers
The most significant feature of of this plugin is context sensitive url_helpers.
Given this routing table
map.resources :changes
map.resources :releases do |releases|
releases.resources :changes
end
map.resources :products do |products|
products.resources :releases do |releases|
releases.resources :changes
end
end
The helper changes_path will return /changes, /releases/:release_id/changes or /products/:product_id/releases/:release_id/changes depending on the context the helper is called in.
The context is defined by return value of parent_resource_types().
ex:
if: parent_resource_types => [] then: changes_path => "/changes" if: parent_resource_types => [:release] then: changes_path => "/releases/:release_id/changes" if: parent_resource_types => [:product, :release] then: changes_path => "/products/:product_id/releases/:release_id/changes"
Preloading Parent Resources
The plugin also adds a before filter which loads all the parent resources and assigns them to your controller.
To activate this functionality simply add the preload_parent_resources() call in any controller. When you activated the preloader a parent resource called Project will be a assigned to the @project attribute. The last parent resource will also be assigned to the @parent_resource attribute.
This method also accepts an option hash used for the before_filter.
Copyright © 2008 Simon Menke, released under the MIT license
http://code.google.com/p/sexy-nested-resources/
http://sexy-nested-resources.googlecode.com/svn/trunk/sexy-nested-resources-read-only
Rails' (MIT)
Controllers

Yeah, I am at this stage agreeing with Matt ....
Calling named route helpers in a view gets into a 'stack level too deep'.
For example ...
map.root :controller => "welcome"
<%= linkto 'Root', rootpath %>
This plugin causes hell in the routing table for rails 2. Is this supposed to be rails 2 compatible?