Created
January 1, 2012 11:22
-
-
Save mikekelly/1547058 to your computer and use it in GitHub Desktop.
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
class DashboardController < ResourceController | |
def get | |
# show dashboard | |
end | |
end |
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
class ProjectsController < CollectionController | |
# /projects | |
collection do | |
def get | |
# equivalent of index action | |
end | |
def post | |
# equivalent of create action | |
end | |
end | |
# /projects/:id | |
member do | |
def get | |
# equivalent of show action | |
end | |
def put | |
# equivalent of update action | |
end | |
def delete | |
# equivalent of destroy action | |
end | |
end | |
# /projects/new | |
new_member do | |
def get | |
# equivalent of new action | |
end | |
end | |
# /projects/:id/edit | |
edit_member do | |
def get | |
# equivalent of edit action | |
end | |
end | |
end |
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' replaced by 'collection' | |
# - 'resource' maps one URL pattern to a controller, | |
# the action picked corresponds to HTTP verb | |
# (i.e. GET -> controller#get, POST -> controller#post, PUT -> controller#put, etc..) | |
Example::Application.routes.draw do | |
resource :dashboard # routes request for /dashboard to dashboard_controller, action corresponds to HTTP verb | |
collection :projects do | |
collection :attachments # nested collection e.g. /projects/123/attachments/388 | |
resource :search, :to => :search_projects # nested resource /projects/search?q=foo | |
end | |
resource 'tags/:tag', :to => :tag | |
end |
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
class SearchProjectsController < ResourceController | |
def get | |
# search using params in url | |
end | |
def post | |
# search using params in post request body (e.g. for queries too big for a URL) | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment