Created
June 30, 2011 18:36
-
-
Save derrickreimer/1056877 to your computer and use it in GitHub Desktop.
Document resource route with the option of scoping by version
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
GET /documents/:id(/:version)(.:format) {:action=>"show", :controller=>"documents"} | |
GET /documents/:id(/:version)/edit(.:format) {:action=>"edit", :controller=>"documents"} | |
PUT /documents/:id(/:version)(.:format) {:action=>"update", :controller=>"documents"} | |
DELETE /documents/:id(/:version)(.:format) {:action=>"destroy", :controller=>"documents"} | |
GET /documents/:document_id(/:version)/sections(.:format) {:action=>"index", :controller=>"sections"} | |
POST /documents/:document_id(/:version)/sections(.:format) {:action=>"create", :controller=>"sections"} | |
GET /documents/:document_id(/:version)/sections/new(.:format) {:action=>"new", :controller=>"sections"} | |
GET /documents/:document_id(/:version)/sections/:id/edit(.:format) {:action=>"edit", :controller=>"sections"} | |
GET /documents/:document_id(/:version)/sections/:id(.:format) {:action=>"show", :controller=>"sections"} | |
PUT /documents/:document_id(/:version)/sections/:id(.:format) {:action=>"update", :controller=>"sections"} | |
DELETE /documents/:document_id(/:version)/sections/:id(.:format) {:action=>"destroy", :controller=>"sections"} | |
GET /documents(.:format) {:action=>"index", :controller=>"documents"} | |
POST /documents(.:format) {:action=>"create", :controller=>"documents"} | |
GET /documents/new(.:format) {:action=>"new", :controller=>"documents"} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
resources :documents, :except => [:show, :edit, :update, :destroy] do | |
member do | |
get '(/:version)', :action => :show | |
get '(/:version)/edit', :action => :edit, :as => :edit | |
put '(/:version)', :action => :update | |
delete '(/:version)', :action => :destroy | |
end | |
resources :sections, :path => '(/:version)/sections' | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Is a version mapped to a real piece of data in your database? You don't have to have a table to have a resource, even one you want to nest. So you could nest a version resource within your document resource, then use the :id param to find the version of the document you want to view. The alternative that comes to mind is to just have the version be a parameter at the end of the URL, like ?version=xyz, and then check the params hash in your controller. You can create links to the versions using