问题
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:in
inspect' app/models/user.rb:27:ininspect' app/models/user.rb:27:in
parseXml' 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