问题描述
我尝试在可以查看日志的服务器上使用活动资源.我请求服务器显示一个带有 xml 的订单.
class Orders
o = Hello::Services::Orders.find(o.id)
当我查看他返回的内容时,他以 xml 格式向我发送了正确的对象.
但是当我看到我收到的东西时:
放置====:"把 xml把 xml.inspect
第二个 put 返回
#
但是第三个 puts 给我一个错误:
NoMethodError(当你没想到的时候,你得到了一个 nil 对象!您可能已经预料到 Array 的实例.评估 nil.each 时发生错误):app/models/user.rb:27:in inspect'app/models/user.rb:27:in
inspect'app/models/user.rb:27:in inspect'app/models/user.rb:27:in
parseXml'app/controllers/orders_controller.rb:47:in `order'
所以如果你知道为什么我不能使用我的对象.对我来说,ActiveResource 改变自身接收到的对象中的数据.
好吧,我不知道为什么,但我成功地使用 .to_yaml 打印了我的对象.
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
But the third puts throw me an error:
So if you know why I can't use my object.For me, ActiveResource change itself received data in object.
Ok I don't know why but I succeed to print my object with .to_yaml.
这篇关于活动资源返回 nil 对象的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!