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:
POST
to user/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
)
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')
});
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With