嗨,我正在使用rails和angularjs与angularrailsresourcegem。我需要对我定义的名为"Comment"的rails资源进行自定义发布请求。我试着使用$post方法如下:
Comment.$post('some_method', {comment_id: comment.id, username: username, type: 'mention'}).then(function(result){
console.log(result);
});
它提出了一个请求,但它总是在我所在页面的根目录下发出。所以我想向"/comments/"发出请求,但他试图向"/pients/some_method"发出请求。如果我这样做:
Comment.$post('comments/do_stuff', {comment_id: comment.id, username: username, type: 'mention'}).then(function(result){
console.log(result);
});
它会尝试发布到"patients/comments/some_method",或者我所在页面的根目录。有没有办法告诉它直接发布到资源,而不是通过我当前所在的url上下文?谢谢你的帮助。
您必须使用前面带有/
的路径,否则它将使用相对路径触发操作。试试这个:
Comment.$post('/comments/do_stuff' ....
注意comments
之前的/
。