9 ### Multiple resources (`resources`)
14 # index => GET /photos
15 # new => GET /photos/new
16 # create => POST /photos/new
17 # show => GET /photos/:id
18 # edit => GET /photos/:id/edit
19 # update => PUT /photos/:id
20 # delete => DELETE /photos/:id
30 member { get 'preview' } # /photo/1/preview
31 collection { get 'search' } # /photos/search
33 get 'preview', on: :member # (..same as the first)
39 path_names: { new: 'brand_new' } # /photos/1/brand_new
40 path: 'postings' # /postings
44 except: [:index, :show]
46 shallow: true # also generate shallow routes
48 shallow_prefix: 'secret'
50 ## Single resource (`resource`)
55 # new => GET /coder/new
56 # create => POST /coder/new
58 # edit => GET /coder/edit
59 # update => PUT /coder
60 # delete => DELETE /coder
64 match 'photo/:id' => 'photos#show' # /photo/what-is-it
65 match 'photo/:id', id: /[0-9]+/ # /photo/0192
66 match 'photo/:id' => 'photos#show', constraints: { id: /[0-9]+/ }
67 match 'photo/:id', via: :get
68 match 'photo/:id', via: [:get, :post]
70 match 'photo/*path' => 'photos#unknown' # /photo/what/ever
72 # params[:format] == 'jpg'
73 match 'photos/:id' => 'photos#show', :defaults => { :format => 'jpg' }
77 `get` is the same as `match via: :get`.
79 get 'photo/:id' => 'photos#show'
80 # same as match 'photo/:id' => 'photos#show', via: :get
82 post 'photo/:id' => 'photos#update'
83 # same as match 'photo/:id' => 'photos#show', via: :post
87 match '/stories' => redirect('/posts')
88 match '/stories/:name' => redirect('/posts/%{name}')
93 match 'exit' => 'sessions#destroy', as: :logout
97 match '/', constraints: { subdomain: 'admin' }
99 # admin.site.com/admin/photos
101 constraints subdomain: 'admin' do
106 ### Custom constraints
108 class BlacklistConstraint
110 @ips = Blacklist.retrieve_ips
113 def matches?(request)
114 @ips.include?(request.remote_ip)
118 TwitterClone::Application.routes.draw do
119 match "*path" => "blacklist#index",
120 :constraints => BlacklistConstraint.new
125 scope 'admin', constraints: { subdomain: 'admin' } do
131 # Yes, Sprockets is middleware
132 match '/application.js' => Sprockets
136 projects_path # /projects
137 projects_url # http://site.com/projects
140 ### Default help text
142 # The priority is based upon order of creation:
143 # first created -> highest priority.
145 # Sample of regular route:
146 match 'products/:id' => 'catalog#view'
148 # Keep in mind you can assign values other than :controller and :action
150 # Sample of named route:
151 match 'products/:id/purchase' => 'catalog#purchase', :as => :purchase
153 # This route can be invoked with purchase_url(:id => product.id)
155 # Sample resource route (maps HTTP verbs to controller actions automatically):
158 # Sample resource route with options:
159 resources :products do
170 # Sample resource route with sub-resources:
171 resources :products do
172 resources :comments, :sales
176 # Sample resource route with more complex sub-resources
177 resources :products do
180 get 'recent', :on => :collection
184 # Sample resource route within a namespace:
186 # Directs /admin/products/* to Admin::ProductsController
187 # (app/controllers/admin/products_controller.rb)
191 # You can have the root of your site routed with "root"
192 # just remember to delete public/index.html.
193 root :to => 'welcome#index'
195 # See how all your routes lay out with "rake routes"
197 # This is a legacy wild controller route that's not recommended for RESTful applications.
198 # Note: This route will make all actions in every controller accessible via GET requests.
199 match ':controller(/:action(/:id(.:format)))'
203 * [Guides/Routing](http://guides.rubyonrails.org/routing.html)
205 * [ActionDispatch::Routing::Mapper](http://api.rubyonrails.org/classes/ActionDispatch/Routing/Mapper.html)
206 (See included modules)