Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save matthewrpacker/891ca52390e9bbb5ca59353ce4673d05 to your computer and use it in GitHub Desktop.
Save matthewrpacker/891ca52390e9bbb5ca59353ce4673d05 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 directs the HTTP request to the appropriate controller.
  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?
  • This represents the root path of your web app. Basically, it is the '/' path that a user get be directed to when the enter in the address of your web app. This page would most likely display a list of all "items".
  1. What rake task is useful when looking at routes, and what information does it give you?
  • $ rake routes
  • Enerting the above in the command line will display all routes available in the app.
  1. How would you interpret this output: items GET /items(.:format) items#index
  • Starting from left to right...
  • items represents the route name. This makes it easier to add links to a webpage, because you can enter link_to "items", items
    • This is helpful in making each link dynamic, accomating for later changes in the app.
  • GET is the HTTP verb
  • /items is the url or path
  • (.format) specifies that is acceptable to add a file extension (e.g. .txt) at the end of the route, but not required
  • items#index is the controller action
  1. What is one major similiarity between Rails routing + controllers and the Sinatra projects we've been building?
  • The HTTP verbs and routes are consistent. MY understanding is that for Rails, we extract the HTTP verb and route/path to it's own file that lives in the config directory. The config directory is the first place that is accessed in the web app, therefore is makes sense to have all routes defined in that file.
  1. What is one major difference between Rails routing + controllers and the Sinatra projects we've been building?
  • In Rails, methods in the controller are defined, rather than inherited.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment