- The router looks at the HTTP verb and URL, and matches it with the right controller action. It also saves any parameters that came with the request in a hash called params. You can type
rake routes
to view all routes available.
- All seven "RESTful" routes: index, show, new, create, edit, update, destroy
- This tells Rails to use the items controller and to go that root/index
- You would access this route in a web app by going to
get "/items"
rake routes
allows you to view all the routes in a controller file- It will look like this:
edit_post GET /posts/:id/edit(.:format) posts#edit
- From left to right this tells you the name of the route, the HTTP verb, the URL, and the controller action this maps to
- The name of the route is the items root, it takes a GET request, the URL is /items, and the controller action this maps to is items#index
What is one major similiarity between Rails routing + controllers and the Sinatra projects we've been building?
- They have the same core functionality - they both use controllers which interpret HTTP verbs and URLS to hit correct routes
What is one major difference between Rails routing + controllers and the Sinatra projects we've been building?
- In Sinatra you have to manually type out all the routes, whereas it's all packaged into Rails in one line.
- Rails has multiple controllers, while Sinatra has one
- Rails also has helper methods