使用活动资源在rails中调用REST API

时间:2013-06-11 02:00:11

标签: ruby-on-rails activeresource

我正在尝试通过浏览器查询从“rest api”获取数据“”http://abc.com:5555/v1/notifier/base/foo/2013-06-09T20:30Z“”正常工作并返回JSON blob。

在我的models / test.class中我有

class foo::base < ActiveResource::Base

class << self                                                                            
def element_path(id, prefix_options = {}, query_options = nil)                       
prefix_options, query_options = split_options(prefix_options) if query_options.nil?
  "#{prefix(prefix_options)}#{collection_name}/#{id}#{query_string(query_options)}"  
end

def collection_path(prefix_options = {}, query_options = nil)                        
prefix_options, query_options = split_options(prefix_options) if query_options.nil?
"#{prefix(prefix_options)}#{collection_name}#{query_string(query_options)}"        
end
end   

ActiveResource::Base.site = 'http://abc.com:5555/'
self.format = :json

self.collection_name='v1/notifier/base'

def self.search                                                                          

results = []

results << self.find(:one, :from => '/foo/2013-06-09T20:30Z')                          
puts results                                                                             

end    

当我调用它返回的类时 “”ActiveResource :: ResourceNotFound:失败。响应代码= 404.响应消息=未找到。 “” 请帮忙

0 个答案:

没有答案