- What is the purpose of the router in a Rails project?
- The router is used to take the incoming verb & path and find the corresponding controller action to run.
- What routes would be provided to you with the line
resources :items
?
- All seven of the restful routes related to items, which would be:
- GET '/items'
- GET '/items/:id'
- GET '/items/new'
- POST '/items'
- GET '/items/:id/edit'
- PUT '/items/:id'
- DELETE '/items/:id'
- What does
root :to => "items#index"
represent? How would you access that route in a web app?
- When someone goes to the root ('/') of your application, your items controller should load its index view.
- What rake task is useful when looking at routes, and what information does it give you?
- rake routes will give you all of the routes for your application
- It will give you the automatically created helper name for your route along with the verb, the actual route, and the controller action
- How would you interpret this output:
items GET /items(.:format) items#index
- the name of the route is items
- the verb/path combo is GET /items
- (.:format) means that a file extension can be specified at the end of the route (but isn't required)
- the action index from the items controller will be run when someone visits this route
- What is one major similiarity between Rails routing + controllers and the Sinatra projects we've been building?
- They use all the same RESTful routes to define how an application behaves
- What is one major difference between Rails routing + controllers and the Sinatra projects we've been building?
- We no longer have to write out every single route we want to use!