Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save stevepentler/8742fcb3161694d2e35a to your computer and use it in GitHub Desktop.
Save stevepentler/8742fcb3161694d2e35a 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?

    • A router redirects the incoming HTTP request to the appropriate controller. It determines what type of information will be displayed and in what context we want to view the information (ex: to view / edit).
  2. What routes would be provided to you with the line resources :items?

    • Resources establishes the seven RESTful routes for the controller.
      • get "/items" => "items#index" INDEX
      • get "/items/:id" => "items#show" SHOW
      • get "/items/new" => "items#new" NEW
      • post "/items" => "items#create" CREATE # usually a submitted form
      • get "/items/:id/edit" => "items#edit" EDIT
      • put "/items/:id" => "items#update" UPDATE # usually a submitted form
      • delete "/items/:id" => "items#destroy" DESTROY
  3. What does root :to => "items#index" represent? How would you access that route in a web app?

    • This represents that you want your root path to perform the index method within the kitten controller. This will perform a GET request display a list of items, which can be accessed by typing in the base url without any additional paths.
  4. What rake task is useful when looking at routes, and what information does it give you?

    • rake routes - gives you a list of available routes within your application.
  5. How would you interpret this output: items GET /items(.:format) items#index

    • Within the items controller, use the GET path to display the index of items and with an optional file extension parameter.
  6. What is one major similiarity between Rails routing + controllers and the Sinatra projects we've been building?

    • With sinatra, we have to define each route explicitly. Also, Sinatra only incorporated GET and POST capabilities, which forced us to create methods in order to execute the other RESTful routes.
  7. What is one major difference between Rails routing + controllers and the Sinatra projects we've been building?

    • First, rails seems to incorporate multiple controllers, which is something we haven't explored. Second, Rails has a lot of undercover magic to set common route paths. Finally, Rails reads better. Using the create route is much easier to distinguish and decipher.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment