Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save ToniRib/a75dfa98d46c01bd850d to your computer and use it in GitHub Desktop.
Save ToniRib/a75dfa98d46c01bd850d 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 is used to take the incoming verb & path and find the corresponding controller action to run.
  1. What routes would be provided to you with the line resources :items?
  • All seven of the restful routes related to items, which would be:
    1. GET '/items'
    2. GET '/items/:id'
    3. GET '/items/new'
    4. POST '/items'
    5. GET '/items/:id/edit'
    6. PUT '/items/:id'
    7. DELETE '/items/:id'
  1. What does root :to => "items#index" represent? How would you access that route in a web app?
  • When someone goes to the root ('/') of your application, your items controller should load its index view.
  1. What rake task is useful when looking at routes, and what information does it give you?
  • rake routes will give you all of the routes for your application
  • It will give you the automatically created helper name for your route along with the verb, the actual route, and the controller action
  1. How would you interpret this output: items GET /items(.:format) items#index
  • the name of the route is items
  • the verb/path combo is GET /items
  • (.:format) means that a file extension can be specified at the end of the route (but isn't required)
  • the action index from the items controller will be run when someone visits this route
  1. What is one major similiarity between Rails routing + controllers and the Sinatra projects we've been building?
  • They use all the same RESTful routes to define how an application behaves
  1. What is one major difference between Rails routing + controllers and the Sinatra projects we've been building?
  • We no longer have to write out every single route we want to use!
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment