Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Ruby on Rails Routes - difference between get and match

What would the difference be?

Example Match:
match 'photos/show' => 'photos#show'

Example Get:
get 'photos/show'

Wouldn't both make it possible to reach the photos/show URL and also use the show action in the photos controller?

Thanks

like image 219
EverTheLearner Avatar asked Aug 08 '11 21:08

EverTheLearner


People also ask

What is match in Rails routes?

Rails routes are matched in the order they are specified, so if you have a resources :photos above a get 'photos/poll' the show action's route for the resources line will be matched before the get line. To fix this, move the get line above the resources line so that it is matched first.

How many types of routes are there in Rails?

Rails RESTful Design which creates seven routes all mapping to the user controller. Rails also allows you to define multiple resources in one line.

How do routes work in Ruby on Rails?

Rails routing is a two-way piece of machinery – rather as if you could turn trees into paper, and then turn paper back into trees. Specifically, it both connects incoming HTTP requests to the code in your application's controllers, and helps you generate URLs without having to hard-code them as strings.

What is the difference between resource and resources?

Singular routes* are a little different – they are written as singular resource . Declaring a resource or resources generally corresponds to generating many default routes. resource is singular. resources is plural.


1 Answers

match matches any http method/verb, while get matches only http method/verb GET.

Following two are equivalent:

match "/signup" => "users#new", :via => [:get] get   "/signup" => "users#new" 
like image 51
rubish Avatar answered Sep 19 '22 00:09

rubish