1.The purpose of the rails router
The rails router recognizes URLS and dispatch them to a controller's action. It's still generate URLs and paths to controller's action,avoid to hardcode.
2.Resource route:the rails default
.One resource route will create seven routes,e.g:
resources
:photos
|
HTTP Verb | Path | action | used for |
---|---|---|---|
GET | /photos | index | display a list of all photos |
GET | /photos/new | new | return an HTML form for creating a new photo |
POST | /photos | create | create a new photo |
GET | /photos/:id | show | display a specific photo |
GET | /photos/:id/edit | edit | return an HTML form for editing a photo |
PUT | /photos/:id | update | update a specific photo |
DELETE | /photos/:id | destroy | delete a specific photo |