Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save GSmes/0906a9c2197fd76482d4424d5ef4d074 to your computer and use it in GitHub Desktop.
Save GSmes/0906a9c2197fd76482d4424d5ef4d074 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 looks at the HTTP verb (GET, POST, PUT, or DELETE) and the URL that is being requested, and matches it with the appropriate controller action to run.
  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"
  1. What does root :to => "items#index" represent? How would you access that route in a web app?
  • It represents the root of the web app. It defines which controller ('items') and action ('index') to map the route to. So when you navigate to http://www.mywebapp.com, you will be taken to the app's root/index page.
  1. What rake task is useful when looking at routes, and what information does it give you?
  • rake routes outputs all of the routes your application knows.
  1. How would you interpret this output: items GET /items(.:format) items#index
  • The name of the route is items. The route itself is the incoming HTTP verb GET to the path called /items, which may contain a format (e.g., .doc), and the controller action it maps to is index (the controller-action combination is items#index).
  1. What is one major similiarity between Rails routing + controllers and the Sinatra projects we've been building?
  • The routes and controllers are all the same. For example, GET requests to the app root display the app's index/dashboard.
  1. What is one major difference between Rails routing + controllers and the Sinatra projects we've been building?
  • Rather than setting up the controller to direct the paths manually, they are already set up for us.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment