Tasteful Routes

An opinionated variation of the standard Rails RESTful routes that has singular member action URLs.

Installation

In your Gemfile:

gem "tasteful_routes"

Usage

Simply define your routes with tasteful_resources as you normally would with the resources method:

YourApp::Application.routes.draw do
  tasteful_resources :jobs
end

This results in the following routes:

    jobs GET    /jobs(.:format)         {:controller=>"jobs", :action=>"index"}
         POST   /jobs(.:format)         {:controller=>"jobs", :action=>"create"}
 new_job GET    /job/new(.:format)      {:controller=>"jobs", :action=>"new"}
edit_job GET    /job/:id/edit(.:format) {:controller=>"jobs", :action=>"edit"}
     job GET    /job/:id(.:format)      {:controller=>"jobs", :action=>"show"}
         PUT    /job/:id(.:format)      {:controller=>"jobs", :action=>"update"}
         DELETE /job/:id(.:format)      {:controller=>"jobs", :action=>"destroy"}

It should work with all the same options as resources, including nesting:

YourApp::Application.routes.draw do
  tasteful_resources :jobs do
    tasteful_resources :items
  end
end

This time resulting in:

    job_items GET    /job/:job_id/items(.:format)         {:controller=>"items", :action=>"index"}
              POST   /job/:job_id/items(.:format)         {:controller=>"items", :action=>"create"}
 new_job_item GET    /job/:job_id/item/new(.:format)      {:controller=>"items", :action=>"new"}
edit_job_item GET    /job/:job_id/item/:id/edit(.:format) {:controller=>"items", :action=>"edit"}
     job_item GET    /job/:job_id/item/:id(.:format)      {:controller=>"items", :action=>"show"}
              PUT    /job/:job_id/item/:id(.:format)      {:controller=>"items", :action=>"update"}
              DELETE /job/:job_id/item/:id(.:format)      {:controller=>"items", :action=>"destroy"}
         jobs GET    /jobs(.:format)                      {:controller=>"jobs", :action=>"index"}
              POST   /jobs(.:format)                      {:controller=>"jobs", :action=>"create"}
      new_job GET    /job/new(.:format)                   {:controller=>"jobs", :action=>"new"}
     edit_job GET    /job/:id/edit(.:format)              {:controller=>"jobs", :action=>"edit"}
          job GET    /job/:id(.:format)                   {:controller=>"jobs", :action=>"show"}
              PUT    /job/:id(.:format)                   {:controller=>"jobs", :action=>"update"}
              DELETE /job/:id(.:format)                   {:controller=>"jobs", :action=>"destroy"}

Maintainers

License

Copyright 2011 Icelab icelab.com.au

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.