- What is the purpose of the router in a Rails project?
- It handles where a request goes by matching the HTTP verb from the request with the appropriate controller action.
- What routes would be provided to you with the line
resources :items
?
get /items => items#index
get /items/new => items#new
post /items => items#create
get /items/:id => items#show
get /items/:id/edit => items#edit
patch/put /items/:id => items#update
delete /items/:id => items#destroy
- What does
root :to => "items#index"
represent? How would you access that route in a web app?
- Tells the application to use the items controller and the index action when the root url is navigated to (i.e., www.mysite.com)
- What rake task is useful when looking at routes, and what information does it give you?
rake routes
. It will show you all the routes for your application.
- How would you interpret this output:
items GET /items(.:format) items#index
- A request of verb GET sent to
/items
is allowed to end in a file extension, and it would trigger the index action.
- What is one major similiarity between Rails routing + controllers and the Sinatra projects we've been building?
- The routes and actions are essentially the same. Rails routing is automating the process of creating our routes, which we have been doing manually with Sinatra.
- What is one major difference between Rails routing + controllers and the Sinatra projects we've been building?
- We no longer have to do it manually (though I will look forward to learning more about how we can better control the actions that take place within each route, since we currently have full control of that within Sinatra).