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

喜你入骨 提交于 2019-12-07 04:02:51

问题


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)


回答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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!