Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ruby-on-rails/55.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/arrays/12.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ruby on rails 如何从Ruby哈希中获取项目?_Ruby On Rails_Arrays_Ruby_Hash - Fatal编程技术网

Ruby on rails 如何从Ruby哈希中获取项目?

Ruby on rails 如何从Ruby哈希中获取项目?,ruby-on-rails,arrays,ruby,hash,Ruby On Rails,Arrays,Ruby,Hash,我从Google Drive API返回了以下哈希: @export_links= {"application/rtf"=> "https://docs.google.com/feeds/download/documents/export/Export?id=xxx&exportFormat=rtf", "application/vnd.oasis.opendocument.text"=> "https://docs.google.com/feeds/dow

我从Google Drive API返回了以下哈希:

@export_links=
 {"application/rtf"=>
   "https://docs.google.com/feeds/download/documents/export/Export?id=xxx&exportFormat=rtf",
  "application/vnd.oasis.opendocument.text"=>
   "https://docs.google.com/feeds/download/documents/export/Export?id=xxx&exportFormat=odt",
  "text/html"=>
   "https://docs.google.com/feeds/download/documents/export/Export?id=xxx&exportFormat=html",
  "application/pdf"=>
   "https://docs.google.com/feeds/download/documents/export/Export?id=xxx&exportFormat=pdf",
  "application/zip"=>
   "https://docs.google.com/feeds/download/documents/export/Export?id=xxx&exportFormat=zip",
  "application/vnd.openxmlformats-officedocument.wordprocessingml.document"=>
   "https://docs.google.com/feeds/download/documents/export/Export?id=xxxx&exportFormat=docx",
  "text/plain"=>
   "https://docs.google.com/feeds/download/documents/export/Export?id=xxx&exportFormat=txt"},
我可以像这样记录导出链接:

logger.debug  file.export_links
但是,我无法获取文本/普通url,请尝试:

logger.debug  file.export_links["text/plain"]
对于nil:NilClass`,
undefined方法
[]”出现错误


如何获取@export\u链接中的text/plain值

你在找这个吗

@export_links.select { |k, v| v if k == 'text/plain' }


如果您需要第一个匹配项。

什么是
文件.export\u links.class
?@spickermann返回哈希或NilClass第一个想法返回
私有方法
为nil:NilClass选择'called for nil:NilClass`第二个
未定义的方法
find'您的代码示例显示了对
@export\u links
的赋值。它应该包含散列,但是当你尝试这个想法时它是零。
@export_links.find { |k, _| k == 'text/plain' }