提取值并格式化 XML feed Rails3
我从外部站点获得了以下提要,我已通过 httparty 将其引入到我的 Rails3.2 应用程序中。
看来我有一个迟钝的时刻,不知道到底如何格式化/样式它。我需要使用 nokogiri 还是更简单?
["radcheck", [{"attribute_name"=>"User-Password", "batch_user_id"=>nil, "id"=>22, "op"=>":=", "radcheck_serial"=>nil, "raduser_id"=>nil, "username"=>"simon", "value"=>"pass"}, {"attribute_name"=>"User-Password", "batch_user_id"=>nil, "id"=>23, "op"=>":=", "radcheck_serial"=>nil, "raduser_id"=>nil, "username"=>"silver", "value"=>"rain"}.....
I've got the following feed from an external site which I've brought in to my rails3.2 app via httparty.
It would seem I'm having a retarted moment and cannot figure out how on earth to format / style it. Do I need to use nokogiri or is it simpler?
["radcheck", [{"attribute_name"=>"User-Password", "batch_user_id"=>nil, "id"=>22, "op"=>":=", "radcheck_serial"=>nil, "raduser_id"=>nil, "username"=>"simon", "value"=>"pass"}, {"attribute_name"=>"User-Password", "batch_user_id"=>nil, "id"=>23, "op"=>":=", "radcheck_serial"=>nil, "raduser_id"=>nil, "username"=>"silver", "value"=>"rain"}.....
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
给定您的示例数据:
这在我的控制台中有效,因此您应该能够针对您的模板机制进行调整。
Given your sample data:
This works in my console, so you should be able to adapt this for your templating mechanism.
嗯,我认为你所要做的就是循环第二个元素,它是一个哈希数组:
在控制器中:
在视图中:
Hum I think all you have to do is to loop over the 2nd element, which is an array of hash :
In controller :
In view :