Why use matching rather than getting when routing in Rails?

In the Ruby on Rails 3 tutorial, the code uses:

match '/signup', :to => 'users#new' match '/signin', :to => 'sessions#new' match '/signout', :to => 'sessions#destroy' match '/contact', :to => 'pages#contact' match '/about', :to => 'pages#about' match '/help', :to => 'pages#help' 

but not

 get '/signup', :to => 'users#new' get '/signin', :to => 'sessions#new' get '/signout', :to => 'sessions#destroy' get '/contact', :to => 'pages#contact' get '/about', :to => 'pages#about' get '/help', :to => 'pages#help' 

although all routes require only an HTTP GET verb. Why not use get (or :via => [:get] on match ) and limit the effect of routing as practical?

+11
ruby-on-rails-3 routes
Dec 23 '11 at 18:31
source share
1 answer

I find it better to use get [...] instead of match . As you mentioned correctly, match will create GET and POST routes. Why create them if you don't need them?

Using the correct matches (receiving or publishing) allows your routes to be cleaned and helps prevent your application from unwanted behavior. The latter applies, in particular, to POST routes, where you do not want to accidentally put a link to a GET request on your web page, which search robots can monitor.

Update [2013-05-12]: Starting with Rails 4.0, you must now explicitly specify the request method .

+22
Dec 23 '11 at 19:35
source share



All Articles