我需要做些什么才能让Hash.from_xml()工作? [英] What do I need to do to get Hash.from_xml() to work?
本文介绍了我需要做些什么才能让Hash.from_xml()工作?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在代码中安装了'ActiveSupport'并要求'active_support',但是当我尝试使用 Hash.from_xml()
时,我得到了No Method Error
我缺少什么?
$ gem list
返回:
\ *** LOCAL GEMS \ ***
activesupport(3.2.6)
bundler(1.1.4)
i18n(0.6.0)
json(1.7.3)
mime-types(1.19)
multi_json(1.3.6)
rake(0.9.2.2)
rest-client(1.6。 7)
rubygems-bundler(1.0.3)
rvm(1.11.3.5)
返回:
ruby 1.9.3p194(2012-04-20修订版35410 )[x86_64-darwin11.4.0]
file.rb
是:
需要'active_support'
需要'rest-client'
需要'json'
token =xxx
user =xxx
survey_id =xxx
respond_from_api = RestClient.gethttps://survey.qualtrics.com/WRAPI/ControlPanel /api.php?Request=getLegacyResponseData&User=#{user}&Token=#{token}&Version=2.0&SurveyID=#{survey_id}&Format=XML
responses =哈希。 from_xml(responses_from_api).to_json
放置回应
和:
$ ruby file.rb
返回:
file.rb:8:在< main>中:未定义方法from_xml for Hash:Class (NoMethodError)
解决方案 'active_support'并没有太大用处,你必须手动完成这些部分。如果你想要所有的ActiveSupport:
require'active_support / all'
或者你只是想要哈希扩展名:
require 'active_support / core_ext / hash'
I installed 'ActiveSupport' and required 'active_support' in my code, but I get a "No Method Error" when I try to use the Hash.from_xml()
method.
What am I missing?
$ gem list
returns:
\*** LOCAL GEMS \***
activesupport (3.2.6)
bundler (1.1.4)
i18n (0.6.0)
json (1.7.3)
mime-types (1.19)
multi_json (1.3.6)
rake (0.9.2.2)
rest-client (1.6.7)
rubygems-bundler (1.0.3)
rvm (1.11.3.5)
And:
$ ruby -v
returns:
ruby 1.9.3p194 (2012-04-20 revision 35410) [x86_64-darwin11.4.0]
The contents of file.rb
are:
require 'active_support'
require 'rest-client'
require 'json'
token = "xxx"
user = "xxx"
survey_id = "xxx"
responses_from_api = RestClient.get "https://survey.qualtrics.com/WRAPI/ControlPanel/api.php?Request=getLegacyResponseData&User=#{user}&Token=#{token}&Version=2.0&SurveyID=#{survey_id}&Format=XML"
responses = Hash.from_xml(responses_from_api).to_json
puts responses
And:
$ ruby file.rb
returns:
file.rb:8:in `<main>': undefined method `from_xml' for Hash:Class (NoMethodError)
解决方案
Just require 'active_support'
doesn't do very much, you have to pull in the pieces sort of by hand. If you want all of ActiveSupport:
require 'active_support/all'
or if you just want the Hash extensions:
require 'active_support/core_ext/hash'
这篇关于我需要做些什么才能让Hash.from_xml()工作?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文