2014-02-12 44 views
0

時才起作用我有一個奇怪的問題,我將一個xml字符串轉換爲hash與simpleXML。錯誤:我的每個循環只有在我寫<%= debug ...%>

但是,當我嘗試將子散列或數組「屬性」內循環,這是行不通的,這裏是HASH:

{ 
    "softwares" => { "type" =>"text", "multiple" =>"true" }, 
    "edition_first_date" => { "type" =>"date" }, 
    "edition_last_date" => { "type" =>"date" }, 
    "documents_date_begin" => { "type" =>"date" }, 
    "documents_date_end" => { "type" =>"date" }, 
    "data_collection_date_begin" => { "type" =>"date" }, 
    "data_collection_date_end" => { "type" =>"date" }, 
    "rec_id" => { "type" =>"hidden" }, 
    "title" => { "type" =>"text", "multiple" =>"false" }, 
    "documents_count" => { "type" =>"hidden" }, 
    "archive_extent" => { "type" =>"text", "multiple" =>"false" }, 
    "archive_location" => { "type" =>"text", "multiple" =>"false" }, 
    "access_conditions" => { "type" =>"text", "multiple" =>"true" }, 
    "association" => { 
    "name" =>"distributors", 
    "label" =>"distributors", 
    "properties" => { "property" => [ 
     { "name" =>"person_distributors", "class_name" =>"Person" }, 
     { "name" =>"orgunit_distributors", "class_name" =>"Orgunit" } 
    ] } 
    } 
} 

這裏是我的模板代碼,當我嘗試環路該屬性,它只需要第一個屬性,我不知道爲什麼,當我添加<%= debug v ['properties'] ['property']%>它需要所有屬性...,這很奇怪。

<% studyHash['step1'].each do |k, v|%> 
    <% if k == 'association' %> 

     <div id="<%=v['label']%>"> 

      <h4><%=v['label']%></h4> 

      <a class="add-<%=v['label']%>" data-toggle="modal">add</a 

      <%= debug v['properties']['property']%> 

      <% v['properties']['property'].each do |k|%> 

       <%=k%> 

       <%=link_to_add_association(' ', f, k['name'].to_sym, :partial=>'/studies/'+k['class_name'].to_s().downcase+'_fields', :data => {"association-insertion-method" => "append" })%> 

      <%end%> 

     </div> 

你能幫我嗎?

回答

相關問題