Sexy Nested ResourcesInstallationscript/plugin install http://sexy-nested-resources.googlecode.com/svn/trunk/sexy_nested_resources Determination of parent resourcesThis 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
endparent_resource_types() will return [:product, :release] for /products/:product_id/releases/:release_id/changes and [] for /changes Sexy Context Sensitive url_helpersThe 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
endThe 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 ResourcesThe 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 (c) 2008 Simon Menke, released under the MIT license
|