问题
I'm dong some quick testing with the Sails framework for Node.
I like the way default CRUD-operations work out of the box, once a model and a controller (e.g.: for user
) are created.
I'm having a bit trouble with extending the basics though.
Say:
- I've created a User-model and empty User-controller.
- This should give me default Rest and Crud operations.
- I've defined a user-signup form that does as
POST
touser/create
. This functionality is defined out of the box.
This works, but results in displaying the created JSON at user/create
.
How do I extend this to redirect to a certain url for example the user profile? (e.g.: GET user
)
回答1:
You will need your own controller method. It could be as simple as below.
create: function(req, res) {
User.create(req.body).exec(function(err, result){
if (err) {
//Handle Error
}
return res.redirect('/somewhere')
});
}
来源:https://stackoverflow.com/questions/23155570/sails-how-to-redirect-after-creating-a-model-with-the-built-in-crud-operations