使用Iron Router从Ruby发布到Meteor? [英] POST from Ruby to Meteor with Iron Router?
问题描述
我一直在尝试从Ruby脚本获取消息到使用POST使用MeteorJS构建的webapp,但我一直面临一些问题。关于使用Iron Router的POST和GET方法管理的在线文档不多。
I've been trying to get a message from a Ruby script to a webapp built with MeteorJS using POST, but I've been facing some issues. There isn't much documentation online about POST and GET method management with Iron Router.
我的Ruby脚本:
meteorUri = URI('http://localhost:3000/newReport');
res = Net::HTTP.post_form(meteorUri, 'message' => 'HelloFromRuby', 'max' => '50')
puts "From Meteor:\t#{res}"
我对Ruby没有多少经验。我上面的代码主要是在线。
I don't have much experience with Ruby. The above code I got mostly online.
使用铁路由器的路由:
Router.route('/newReport/:message', {where: 'server'})
.post( function(message){
Meteor.call('reportInsert', {message: message}, function(error, recordId){
if (error){
alert(error.reason);
} else {
console.log("Inserted " + recordId);
}
});
});
我想让Ruby发帖到 http:// localhost :3000 / newReport
,带有一个应该是字符串的消息。
I am trying to make Ruby make a post to http://localhost:3000/newReport
with a message that is supposed to be a string.
函数 reportInsert
有效,我测试了它。问题似乎在于发布POST或接收它。
The function reportInsert
works, I tested it. The issue seems to be in either making the POST, or receiving it.
谢谢!
推荐答案
除了在服务器端路由中使用警报外,我在Meteor方面没有看到任何问题。可能想将其更改为console.log以查看您获得的错误。
Beside using an alert in a server side route, I don't see any issues on Meteor's side. Might want to change it to console.log to see what error are you getting.
这篇关于使用Iron Router从Ruby发布到Meteor?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!