Gist a4fc97b892cb0bc1b81b1e548b3b8149
✓ Published0🌍 Public
Aabernier
Last edited Dec 27, 2019
Created on Dec 19, 2019
This example demonstrates Ruby on Rails routing conventions by pairing an HTTP verb/path reference table with Express.js controller and router code. The README table maps CRUD actions to standard Rails routes, while the JavaScript files show equivalent Express implementations using `express.Router()`, `router.get()`, `router.put()`, `router.head()`, and `router.delete()` to define endpoints like `/photos` and `/photos/:id`. The controller file exports handler functions such as `index`, `show`, and `validate`, illustrating how routes delegate to named actions. The code uses the Express framework to mirror Rails’ RESTful design patterns.
AI-generated descriptionExpress controllers/routes conventions
| HTTP Verb | Path | Controller#Action | Used for |
|---|---|---|---|
GET |
/photos |
photos#index |
display a list of all photos |
PUT |
/photos/:id/valid OR /photos/valid |
photos#validate |
tell whether the passed data are valid (204 or 422) |
HEAD |
/photos/:id OR /photos?people=Sam |
photos#exist |
tell whether that photo exists (204 or 404) |
GET |
/photos/new |
photos#new |
return an HTML form for creating a new photo |
POST |
/photos |
photos#create |
create a new photo |
GET |
/photos/:id |
photos#show |
display a specific photo |
GET |
/photos/:id/edit |
photos#edit |
return an HTML form for editing a photo |
PATCH/PUT |
/photos/:id |
photos#update |
update a specific photo |
DELETE |
/photos/:id |
photos#destroy |
delete a specific photo |
see: https://guides.rubyonrails.org/routing.html#crud-verbs-and-actions