rails从gem返回的hashie中提取变量

时间:2013-02-27 03:01:09

标签: ruby-on-rails ruby api rails-console

我正在使用名为Desk的gem来从desk.com的API返回数据。当我运行Desk.customers(:custom_external_id => temp.id)时,它会返回一组可爱的数据。

我正在寻找id=71095620的整数71095620。

   => #<Hashie::Rash count=20 page=1 results=[#<Hashie::Rash customer=#<Hashie::Rash addresses=[] custom_external_id="58749" emails=[#<Hashie::Rash email=#<Hashie::Rash created_at="2013-02-13T15:59:26-08:00" email="CENSORED" i
d=33622514 updated_at="2013-02-13T15:59:26-08:00" verified_at=nil>>] first_name="CENSORED" id=68712186 language=nil last_name="CENSORED" phones=[#<Hashie::Rash phone=#<Hashie::Rash created_at="2013-02-13T16:00:45-08:00" id=1301079 phone="CENSORED" updated_at="2013-02-13T16:00:45-08:00">>] twitters=[nil]>>, #<Hashie::Rash customer=#<Hashie::Rash addresses=[] custom_external_id="58749"  emails=[] first_name="CENSORED" id=71095620 language=nil last_name="CENSORED" phones=[] twitters=[nil]>>] total=2> 

这显然有多个id字段,我不知道哪种方式最好提取整数。提前谢谢!

1 个答案:

答案 0 :(得分:2)

根据Hasie::Rash readme,您可以这样做

response = Desk.customers(:custom_external_id => temp.id)
response.results[1].customer.id