6 ## Multiple resources (`resources`)
11 # index => GET /photos
12 # new => GET /photos/new
13 # create => POST /photos/new
14 # show => GET /photos/:id
15 # edit => GET /photos/:id/edit
16 # update => PUT /photos/:id
17 # delete => DELETE /photos/:id
27 member { get 'preview' } # /photo/1/preview
28 collection { get 'search' } # /photos/search
30 get 'preview', on: :member # (..same as the first)
36 path_names: { new: 'brand_new' } # /photos/1/brand_new
37 path: 'postings' # /postings
41 except: [:index, :show]
43 shallow: true # also generate shallow routes
45 shallow_prefix: 'secret'
47 ## Single resource (`resource`)
52 # new => GET /coder/new
53 # create => POST /coder/new
55 # edit => GET /coder/edit
56 # update => PUT /coder
57 # delete => DELETE /coder
61 match 'photo/:id' => 'photos#show' # /photo/what-is-it
62 match 'photo/:id', id: /[0-9]+/ # /photo/0192
63 match 'photo/:id' => 'photos#show', constraints: { id: /[0-9]+/ }
64 match 'photo/:id', via: :get
65 match 'photo/:id', via: [:get, :post]
67 match 'photo/*path' => 'photos#unknown' # /photo/what/ever
69 # params[:format] == 'jpg'
70 match 'photos/:id' => 'photos#show', :defaults => { :format => 'jpg' }
74 `get` is the same as `match via: :get`.
76 get 'photo/:id' => 'photos#show'
77 # same as match 'photo/:id' => 'photos#show', via: :get
79 post 'photo/:id' => 'photos#update'
80 # same as match 'photo/:id' => 'photos#show', via: :post
84 match '/stories' => redirect('/posts')
85 match '/stories/:name' => redirect('/posts/%{name}')
90 match 'exit' => 'sessions#destroy', as: :logout
94 match '/', constraints: { subdomain: 'admin' }
96 # admin.site.com/admin/photos
98 constraints subdomain: 'admin' do
103 ### Custom constraints
105 class BlacklistConstraint
107 @ips = Blacklist.retrieve_ips
110 def matches?(request)
111 @ips.include?(request.remote_ip)
115 TwitterClone::Application.routes.draw do
116 match "*path" => "blacklist#index",
117 :constraints => BlacklistConstraint.new
122 scope 'admin', constraints: { subdomain: 'admin' } do
128 # Yes, Sprockets is middleware
129 match '/application.js' => Sprockets
133 projects_path # /projects
134 projects_url # http://site.com/projects
137 ### Default help text
139 # The priority is based upon order of creation:
140 # first created -> highest priority.
142 # Sample of regular route:
143 match 'products/:id' => 'catalog#view'
145 # Keep in mind you can assign values other than :controller and :action
147 # Sample of named route:
148 match 'products/:id/purchase' => 'catalog#purchase', :as => :purchase
150 # This route can be invoked with purchase_url(:id => product.id)
152 # Sample resource route (maps HTTP verbs to controller actions automatically):
155 # Sample resource route with options:
156 resources :products do
167 # Sample resource route with sub-resources:
168 resources :products do
169 resources :comments, :sales
173 # Sample resource route with more complex sub-resources
174 resources :products do
177 get 'recent', :on => :collection
181 # Sample resource route within a namespace:
183 # Directs /admin/products/* to Admin::ProductsController
184 # (app/controllers/admin/products_controller.rb)
188 # You can have the root of your site routed with "root"
189 # just remember to delete public/index.html.
190 root :to => 'welcome#index'
192 # See how all your routes lay out with "rake routes"
194 # This is a legacy wild controller route that's not recommended for RESTful applications.
195 # Note: This route will make all actions in every controller accessible via GET requests.
196 match ':controller(/:action(/:id(.:format)))'
200 * [Guides/Routing](http://guides.rubyonrails.org/routing.html)
202 * [ActionDispatch::Routing::Mapper](http://api.rubyonrails.org/classes/ActionDispatch/Routing/Mapper.html)
203 (See included modules)