Skip to content

Instantly share code, notes, and snippets.

@mikekelly
Created January 1, 2012 11:22
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mikekelly/1547058 to your computer and use it in GitHub Desktop.
Save mikekelly/1547058 to your computer and use it in GitHub Desktop.
class DashboardController < ResourceController
def get
# show dashboard
end
end
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
# - '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
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