帆:如何在使用内置 crud 操作创建模型后重定向? [英] sails: how to redirect after creating a model with the built-in crud operations?
问题描述
我正在使用 Node.js 的 Sails 框架进行一些快速测试.
I'm dong some quick testing with the Sails framework for Node.
我喜欢默认 CRUD 操作开箱即用的方式,一旦创建了模型和控制器(例如:对于 user
).
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.
说:
- 我已经创建了一个用户模型和空的用户控制器.
- 这应该给我默认的 Rest 和 Crud 操作.
- 我已经定义了一个用户注册表单,它的作用类似于
POST
到user/create
.此功能是开箱即用的.
- 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.
这可行,但会导致在 user/create
处显示创建的 JSON.我如何扩展它以重定向到某个 url,例如用户个人资料?(例如:GET user
)
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')
});
}
这篇关于帆:如何在使用内置 crud 操作创建模型后重定向?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!