我是CompoundJS新手,我不太确定这是否是正确的行为。
我以PROD模式启动服务器,代码如下:
NODE_ENV=production compound server 8081
然后我撞到:
http://localhost:8081/categories/
我很想看到从服务器中检索到一些JSON。
相反,它呈现如下页面:

发布于 2013-06-07 22:02:28
正如@Pablo在注释中提到的,只需在对控制器的调用中使用.json即可。
如下所示:
GET http://localhost:3000/categories.json预期您的控制器将同时处理这两种情况,就像生成的控制器一样。
一个具体的例子:[approot]/app/controllers/category_controller.js
在JavaScript中:
action(function index() {
this.title = 'Categories index';
Category.all(function (err, categories) {
respondTo(function (format) {
// Use format.json and the send method to return JSON data when
// .json is specified at the end of the controller
format.json(function () {
send({code: 200, data: categories});
});
format.html(function () {
render({
categories: categories
});
});
});
});
});在CoffeeScript中:
action index = ->
@title = "Categories index"
Category.all (err, categories) ->
respondTo (format) ->
# Use format.json and the send method to return JSON data when
# .json is specified at the end of the controller
format.json ->
send
code: 200
data: categories
format.html ->
render categories: categorieshttps://stackoverflow.com/questions/16493632
复制相似问题