Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save zackforbing/e6e3a97c338f163b09178d78be801f1b to your computer and use it in GitHub Desktop.
Save zackforbing/e6e3a97c338f163b09178d78be801f1b to your computer and use it in GitHub Desktop.
Intro to Rails Routing Warm-Up Questions
  1. What is the purpose of the router in a Rails project?

The Router in rails is essentially a matching service. it matches the request (path and verb) to a corresponding route for our project.

  1. What routes would be provided to you with the line resources :items?
get "/items" => "items#index"
get "/items/:id" => "items#show"
get "/items/new" => "items#new"
post "/items" => "items#create"
get "/items/:id/edit" => "items#edit"
put "/items/:id" => "items#update" #
delete "/items/:id" => "items#destroy"

aka, the seven RESTful routes.

  1. What does root :to => "items#index" represent? How would you access that route in a web app?

it represents the root url. so when you go to the root url it would direct you there.

  1. What rake task is useful when looking at routes, and what information does it give you?
rake routes

this makes Rails output all of your routes into the command line.

  1. How would you interpret this output: items GET /items(.:format) items#index

the "name" of the route on the left, the HTTP verb and path following, and the controller action at the end.

  1. What is one major similiarity between Rails routing + controllers and the Sinatra projects we've been building?

the routes all go to controller actions, which we have had good experience defining in Rush Hour :)

  1. What is one major difference between Rails routing + controllers and the Sinatra projects we've been building?

Rails routing seems pretty automatic compared to what we've been doing in sinatra, and it makes the routing we were doing in HTTPYYKM look like we made it out of a baby's alphabet blocks. the seven RESTful paths are automatically set up, and you actually have to tell it NOT to create them if you only want certain paths.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment