Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save dtinianow/fe48cbe1b2e308c7535c83cd8746cc53 to your computer and use it in GitHub Desktop.
Save dtinianow/fe48cbe1b2e308c7535c83cd8746cc53 to your computer and use it in GitHub Desktop.
Intro to Rails Routing Warm-Up Questions
What is the purpose of the router in a Rails project?
  • The router looks at the HTTP verb and URL, and matches it with the right controller action. It also saves any parameters that came with the request in a hash called params. You can type rake routes to view all routes available.
What routes would be provided to you with the line resources :items?
  • All seven "RESTful" routes: index, show, new, create, edit, update, destroy
What does root :to => "items#index" represent? How would you access that route in a web app?
  • This tells Rails to use the items controller and to go that root/index
  • You would access this route in a web app by going to get "/items"
What rake task is useful when looking at routes, and what information does it give you?
  • rake routes allows you to view all the routes in a controller file
  • It will look like this: edit_post GET /posts/:id/edit(.:format) posts#edit
  • From left to right this tells you the name of the route, the HTTP verb, the URL, and the controller action this maps to
How would you interpret this output: items GET /items(.:format) items#index
  • The name of the route is the items root, it takes a GET request, the URL is /items, and the controller action this maps to is items#index
What is one major similiarity between Rails routing + controllers and the Sinatra projects we've been building?
  • They have the same core functionality - they both use controllers which interpret HTTP verbs and URLS to hit correct routes
What is one major difference between Rails routing + controllers and the Sinatra projects we've been building?
  • In Sinatra you have to manually type out all the routes, whereas it's all packaged into Rails in one line.
  • Rails has multiple controllers, while Sinatra has one
  • Rails also has helper methods
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment