Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

sails: how to redirect after creating a model with the built-in crud operations?

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 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)

like image 329
Geert-Jan Avatar asked Apr 18 '14 13:04

Geert-Jan


1 Answers

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')
  });
}
like image 118
InternalFX Avatar answered Sep 21 '22 05:09

InternalFX