0

I am trying to fetch data from rest api through browser query ""http://abc.com:5555/v1/notifier/base/foo/2013-06-09T20:30Z"" works fine and returns a JSON blob.

in my models/test.class i have

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    

when i call the class it returns ""ActiveResource::ResourceNotFound: Failed. Response code = 404. Response message = Not Found. "" Help please

sorabh
  • 297
  • 1
  • 3
  • 11
  • Could you get the log from the rest service that you are trying to access? – usha Jun 11 '13 at 02:42
  • thats really strange i dont see the expected query in the log. My log looks like. `2013-06-11T16:11:21.382-04:00 10.21.43.173 GET /v1/notifier/base/ null null 404 0 1286 1 d8f99881-b481-45ea-871d-84b0f1698486.` And i expected it to be like /v1/notifier/base/foo/2013-06-09T20:30Z. Why the collection name set by me is not being used?? – sorabh Jun 11 '13 at 20:17
  • Don't you have to give `self.find(:one, :from => '/foo/2013-06-09T20:30Z.json')`? Atleast the documentation says that you have to give it. http://api.rubyonrails.org/classes/ActiveResource/Base.html#method-c-find#method-c-find-label-Examples – usha Jun 11 '13 at 21:43
  • My api dont use.json extension bunch of code `class << self #################### end def collection_path(prefix_options = {}, query_options = nil) ################### end end ` written at the beginning makes sure my call works without .json. – sorabh Jun 11 '13 at 22:28
  • ok i guess i made it to work by giving the full path in the self.find(:one, :from => 'v1/notifier/base/foo/2013-06-09T20:30Z' but now i dont understand if i need collection_name, coz the code returns a whole blob even without collection_name being available ... – sorabh Jun 11 '13 at 23:52

0 Answers0