Not logged in (Log in or Sign up)

SelectiveMapper

Selectively map resource routes to allow cleaner nesting of resources without having to specify redundant ids for parent resources.

IMPORTANT

A patch I submitted to edge rails recently has been accepted.

The update adds a :shallow option to the resources method eliminating my original need for this plugin.

This reduces the example from this document from ...

map.resources :companies do |company|
  company.resources :people, :only => [ :collection, :new ]
end
map.resources :people, :except => [ :collection, :new ]

... to ...

map.resources :companies, :shallow => true do |company|
  company.resources :people
end

... or ...

map.resources :companies, :shallow => true, :has_many => :people

Example

map.resources :companies do |company|
  company.resources :people, :only => [ :collection, :new ]
end
map.resources :people, :except => [ :collection, :new ]

Results in...

                   companies GET    /companies                                {:controller=>"companies", :action=>"index"}
         formatted_companies GET    /companies.:format                        {:controller=>"companies", :action=>"index"}
                             POST   /companies                                {:controller=>"companies", :action=>"create"}
                             POST   /companies.:format                        {:controller=>"companies", :action=>"create"}
                 new_company GET    /companies/new                            {:controller=>"companies", :action=>"new"}
       formatted_new_company GET    /companies/new.:format                    {:controller=>"companies", :action=>"new"}
                edit_company GET    /companies/:id/edit                       {:controller=>"companies", :action=>"edit"}
      formatted_edit_company GET    /companies/:id/edit.:format               {:controller=>"companies", :action=>"edit"}
                     company GET    /companies/:id                            {:controller=>"companies", :action=>"show"}
           formatted_company GET    /companies/:id.:format                    {:controller=>"companies", :action=>"show"}
                             PUT    /companies/:id                            {:controller=>"companies", :action=>"update"}
                             PUT    /companies/:id.:format                    {:controller=>"companies", :action=>"update"}
                             DELETE /companies/:id                            {:controller=>"companies", :action=>"destroy"}
                             DELETE /companies/:id.:format                    {:controller=>"companies", :action=>"destroy"}
              company_people GET    /companies/:company_id/people             {:controller=>"people", :action=>"index"}
    formatted_company_people GET    /companies/:company_id/people.:format     {:controller=>"people", :action=>"index"}
                             POST   /companies/:company_id/people             {:controller=>"people", :action=>"create"}
                             POST   /companies/:company_id/people.:format     {:controller=>"people", :action=>"create"}
          new_company_person GET    /companies/:company_id/people/new         {:controller=>"people", :action=>"new"}
formatted_new_company_person GET    /companies/:company_id/people/new.:format {:controller=>"people", :action=>"new"}
                 edit_person GET    /people/:id/edit                          {:controller=>"people", :action=>"edit"}
       formatted_edit_person GET    /people/:id/edit.:format                  {:controller=>"people", :action=>"edit"}
                      person GET    /people/:id                               {:controller=>"people", :action=>"show"}
            formatted_person GET    /people/:id.:format                       {:controller=>"people", :action=>"show"}
                             PUT    /people/:id                               {:controller=>"people", :action=>"update"}
                             PUT    /people/:id.:format                       {:controller=>"people", :action=>"update"}
                             DELETE /people/:id                               {:controller=>"people", :action=>"destroy"}
                             DELETE /people/:id.:format                       {:controller=>"people", :action=>"destroy"}

Legal

Author: S. Brent Faulkner brentf@unwwwired.net
License: Copyright © 2008 unwwwired.net, released under the MIT license

Source code

github repository