Active Resource return nil object

↘锁芯ラ 提交于 2020-01-24 20:04:54

问题


I try to use active resource with a server where I can see log. I request the server with a show on a order with xml.

class Orders < ActiveResource::Base
  self.site = "http://"+Hello::Services.session.server+"/api/"
  self.element_name = "orders"
  self.format = ActiveResource::Formats::XmlFormat
end

o = Hello::Services::Orders.find(o.id)

When I look what he returns he sends me the correct object in xml.

but when I look what I receive with this:

puts "====:"
puts xml
puts xml.inspect

the second puts return

#< Hello::Services::Orders:0x007fc685339070>

But the third puts throw me an error:

NoMethodError (You have a nil object when you didn't expect it! You might have expected an instance of Array. The error occurred while evaluating nil.each): app/models/user.rb:27:in inspect' app/models/user.rb:27:ininspect' app/models/user.rb:27:in inspect' app/models/user.rb:27:inparseXml' app/controllers/orders_controller.rb:47:in `order'

So if you know why I can't use my object. For me, ActiveResource change itself received data in object.


回答1:


Ok I don't know why but I succeed to print my object with .to_yaml.



来源:https://stackoverflow.com/questions/11098078/active-resource-return-nil-object

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!