Rails 3 中 JSONRPC 的使用
我是 Ruby On Rails 的新手,我需要实现 JSON API 的客户端部分才能使用一些外部服务。
我发现了一个名为 jsonrpc 的 gem,它看起来很适合我。 我已将其添加到我的 Gemfile 中:
gem 'jsonrpc'
gem 'json'
并运行 bundle
我的代码如下所示:
class SearchController < ApplicationController
def index
d = JsonRpcClient.new 'http://remote.bronni.ru/Dictionaries.ashx'
@countries = d.getCountries
end
但是当我尝试以 http://localhost:3000/search
访问它时,Rails 说:
NameError in SearchesController#index
uninitialized constant SearchController::JsonRpcClient
我对 Rails 的经验很少,所以我请求你们帮助我。 我真的需要尽快让它发挥作用。
提前谢谢大家!我真的很感谢你的帮助!
更新
我尝试让 ActiveResource 工作,但我无法了解它如何构建 URL。远程服务不是 Ruby XML 应用程序。 (http://remote.bronni.ru/Dictionaries.ashx)我需要使用getCountries方法,因此URL应该是http://remote。 bronni.ru/Dictionaries.ashx/getCountries
I'm quite a beginner with Ruby On Rails and I need to implement client part of JSON API in order to use some external service.
I found a gem called jsonrpc and it looks perfect for me.
I've added it to my Gemfile as:
gem 'jsonrpc'
gem 'json'
and ran bundle
My code looks like this:
class SearchController < ApplicationController
def index
d = JsonRpcClient.new 'http://remote.bronni.ru/Dictionaries.ashx'
@countries = d.getCountries
end
But when I try to access it as http://localhost:3000/search
, Rails says:
NameError in SearchesController#index
uninitialized constant SearchController::JsonRpcClient
I only have little experience with Rails so I'm asking you guys to help me out.
I really need to get this to work ASAP.
Thank you all in advance! I really appreciate your help!
UPDATE
I've tryed to get ActiveResource to work but I can't get how it build URL's. The remote service is not a Ruby XML app. (http://remote.bronni.ru/Dictionaries.ashx) And I need to use getCountries method so the URL should be http://remote.bronni.ru/Dictionaries.ashx/getCountries
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论