ruby on rails - Trying to display fields from hash but getting undefined method `[]' for nil:NilClass -


i receiving error "undefined method `[]' nil:nilclass" when trying display field json parsed hash. how coll_title data display?

the data alinks:

[{ "role"=>"source",  "relator"=>"dnr",  "terms"=>[],  "_resolved"=>{     "lock_version"=>0,      "publish"=>true,      "display_name"=>{         "coll_num"=>"024",          "coll_title"=>"collection title"         }     } }] 

the code:

def display_agents(hash, opts = {})   html = "<div><small>"   html << "<ul style='list-style-type:none'>"   alinks = json.parse( hash["json"] )["linked_agents"]   alinks.each |_resolved|     html << "<li>#{_resolved["display_name"]["coll_title"]}</li>"   end   html << "</ul>"   html << "</small></div><div class='clearfix'></div>"   html.html_safe end 

the call:

<td>   <% if result['primary_type'] === "resource" or result['primary_type'] === "digital_object" or result['primary_type'] === "accession" %>       <%= display_agents(result) %>   <% end %> </td> 

the error:

undefined method `[]' nil:nilclass  extracted source (around line #85):  82:         <% end %> 83:         <td> 84:           <% if result['primary_type'] === "resource" or result['primary_type'] === "digital_object" or result['primary_type'] === "accession" %> 85:               <%= display_agents(result) %> 86:           <% end %> 87:         </td> 88:         <%#<td>%> 

edit: added method call , error display.

assuming data alinks show linked_agents array (it's not 100% clear question) - need

alinks.each |agent_link|   html << "<li>#{agent_link["_resolved"]["display_name"]["coll_title"]}</li>" end 

Comments

Popular posts from this blog

get url and add instance to a model with prefilled foreign key :django admin -

css - Make div keyboard-scrollable in jQuery Mobile? -

ruby on rails - Seeing duplicate requests handled with Unicorn -