Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save ryanflach/4d8eba389b99156d7be487a99f241bf4 to your computer and use it in GitHub Desktop.
Save ryanflach/4d8eba389b99156d7be487a99f241bf4 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?
  • It handles where a request goes by matching the HTTP verb from the request with the appropriate controller action.
  1. What routes would be provided to you with the line resources :items?
  • get /items => items#index
  • get /items/new => items#new
  • post /items => items#create
  • get /items/:id => items#show
  • get /items/:id/edit => items#edit
  • patch/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?
  • Tells the application to use the items controller and the index action when the root url is navigated to (i.e., www.mysite.com)
  1. What rake task is useful when looking at routes, and what information does it give you?
  • rake routes. It will show you all the routes for your application.
  1. How would you interpret this output: items GET /items(.:format) items#index
  • A request of verb GET sent to /items is allowed to end in a file extension, and it would trigger the index action.
  1. What is one major similiarity between Rails routing + controllers and the Sinatra projects we've been building?
  • The routes and actions are essentially the same. Rails routing is automating the process of creating our routes, which we have been doing manually with Sinatra.
  1. What is one major difference between Rails routing + controllers and the Sinatra projects we've been building?
  • We no longer have to do it manually (though I will look forward to learning more about how we can better control the actions that take place within each route, since we currently have full control of that within Sinatra).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment