Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

add save and delete actions use http method `POST` #10

Closed
wants to merge 1 commit into from

5 participants

fengmk2 Dan Williams Paul Covell andrew morton Andrey Mereskin
fengmk2
Owner

support html form submit for data update. add save and delete actions use http method POST

Dan Williams

Seems like it would be better to handle this up the middleware stack with https://github.com/senchalabs/connect/blob/master/lib/middleware/methodOverride.js

Paul Covell

These can also be done using custom actions, already available. You don't need to modify index.js --

users.map('post', '/save', logoutAction); // (or 'save', if you want the local parameter included)

andrew morton

It does seem like kind of a shame to provide defaults that aren't compatible with forms... But I guess that's the only way that you can do it all on such a small set of URLs.

Andrey Mereskin mereskin closed this
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Apr 22, 2011
  1. fengmk2
This page is out of date. Refresh to see the latest.
Showing with 25 additions and 7 deletions.
  1. +19 −7 Readme.md
  2. +6 −0 index.js
26 Readme.md
View
@@ -36,10 +36,18 @@ npm:
exports.update = function(req, res){
res.send('update forum ' + req.params.id);
};
+
+ exports.save = function(req, res){
+ res.send('save forum ' + req.params.id);
+ };
exports.destroy = function(req, res){
res.send('destroy forum ' + req.params.id);
};
+
+ exports.delete = function(req, res){
+ res.send('delete forum ' + req.params.id);
+ };
The `app.resource()` method returns a new `Resource` object, which can be used to further map pathnames, nest resources, and more.
@@ -53,13 +61,15 @@ The `app.resource()` method returns a new `Resource` object, which can be used t
Actions are then mapped as follows (by default), providing `req.params.forum` which contains the substring where ":forum" is shown below:
- GET /forums -> index
- GET /forums/new -> new
- POST /forums -> create
- GET /forums/:forum -> show
- GET /forums/:forum/edit -> edit
- PUT /forums/:forum -> update
- DELETE /forums/:forum -> destroy
+ GET /forums -> index
+ GET /forums/new -> new
+ POST /forums -> create
+ GET /forums/:forum -> show
+ GET /forums/:forum/edit -> edit
+ PUT /forums/:forum -> update
+ POST /forums/:forum -> save // html form don't support PUT and DELETE
+ DELETE /forums/:forum -> destroy
+ POST /forums/:forum/delete -> delete
## Top-Level Resource
@@ -75,7 +85,9 @@ Top-level actions are then mapped as follows (by default):
GET /:id -> show
GET /:id/edit -> edit
PUT /:id -> update
+ POST /:id -> save
DELETE /:id -> destroy
+ POST /:id/delete -> delete
## Auto-Loading
6 index.js
View
@@ -197,9 +197,15 @@ Resource.prototype.mapDefaultAction = function(key, fn){
case 'update':
this.put(fn);
break;
+ case 'save':
+ this.post(fn);
+ break;
case 'destroy':
this.del(fn);
break;
+ case 'delete':
+ this.post('delete', fn);
+ break;
}
};
Something went wrong with that request. Please try again.