Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save kamiboers/ba5cbf400be6a9d1df1dd73e7d4e145d to your computer and use it in GitHub Desktop.
Save kamiboers/ba5cbf400be6a9d1df1dd73e7d4e145d 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 receives an HTTP request, parses it and matches it with the appropriate controller action to run. In a Rails project it also puts the parameters into a params hash that can be used by the controller and app.

  1. What routes would be provided to you with the line resources :items?

GET all items (index) - get "/items" => "items#index" GET one post (show) - get "/item/:id" => "items#show" GET page to input new item (new) - get "/items/new" => "items#new" POST a new item (create) - post "/items" => "items#create" GET page to edit existing post (edit) - get "/items/:id/edit" => "items#edit" PUT edit of item data (update) - put "/items/:id" => items#update DELETE the item (destroy) - delete "/items/:id" => items#destroy

  1. What does root :to => "items#index" represent? How would you access that route in a web app?

It tells Rails to connect the root url to the items controller and index action (all the posts). You would access it by entering the root or base URL of the application.

  1. What rake task is useful when looking at routes, and what information does it give you?

'rake routes' returns all of the routes available to your application, with their names.

  1. How would you interpret this output: items GET /items(.:format) items#index

It accesses and displays an index of all items.

  1. What is one major similiarity between Rails routing + controllers and the Sinatra projects we've been building?

It uses the same methods that we defined to create CRUD functionality.

  1. What is one major difference between Rails routing + controllers and the Sinatra projects we've been building?

Rails requires only one line of code to access all of the RESTful routes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment