jeudi 23 avril 2015

ruby display 2 dimension array

I am trying to display 2 dimension array. using below code. However for each array's first subscript I have to code one loop. Can I do it using an outer loop instead of multiple loops?

  <% tempTickets = subject['permailaddr-addrline1'] %>  
  <% cnt = tempTickets.length %>
  <% tempTickets.each_with_index do |ticket, index| %>
<div>
<tr>
  <td><li class="entity_info"><div><span class="label"><%= subject['memhead-mem-recno'][index] %></span></div></li></td>
  <td><li class="entity_info"><div><span class="label"><%= subject['permailaddr-addresstype'][index] %></span></div></li></td>
  <td><li class="entity_info"><div><span class="label"><%= subject['permailaddr-addrline1'][index] %></span></div></li></td>
  <td><li class="entity_info"><div><span class="label"><%= subject['permailaddr-state'][index] %></span></div></li></td>
  <td><li class="entity_info"><div><span class="label"><%= subject['permailaddr-suburb'][index] %></span></div></li></td>
  <td><li class="entity_info"><div><span class="label"><%= subject['permailaddr-postcode'][index] %></span></div></li></td>
  <td><li class="entity_info"><div><span class="label"><%= subject['permailaddr-countrycode'][index] %></span></div></li></td>
</tr>
</div>
  <% end %>
  <% tempTickets = subject['perresiaddr-addrline1'] %>  
  <% cnt = tempTickets.length %>
  <% tempTickets.each_with_index do |ticket, index| %>
<div>
<tr>
  <td><li class="entity_info"><div><span class="label"><%= subject['memhead-mem-recno'][index] %></span></div></li></td>
  <td><li class="entity_info"><div><span class="label"><%= subject['perresiaddr-addresstype'][index] %></span></div></li></td>
  <td><li class="entity_info"><div><span class="label"><%= subject['perresiaddr-addrline1'][index] %></span></div></li></td>
  <td><li class="entity_info"><div><span class="label"><%= subject['perresiaddr-state'][index] %></span></div></li></td>
  <td><li class="entity_info"><div><span class="label"><%= subject['perresiaddr-suburb'][index] %></span></div></li></td>
  <td><li class="entity_info"><div><span class="label"><%= subject['perresiaddr-postcode'][index] %></span></div></li></td>
  <td><li class="entity_info"><div><span class="label"><%= subject['perresiaddr-countrycode'][index] %></span></div></li></td>
</tr>
</div>
  <% end %>

Aucun commentaire:

Enregistrer un commentaire