title: How can I iterate through an array in rails view?
body: <p>I did a query in MySql but is working in Rails and mysql2 gem.</p>
  
  <p>Here is the information:</p>
  
  <pre><code>http://sqlfiddle.com/#!2/9adb8/6
  </code></pre>
  
  <p>The query is working fine without problems and showing this result:</p>
  
  <pre><code> UNIT  V1  A1  N1   V2 A2  N2   V3  A3  N3   V4  A4  N4   V5  A5  N5
   LIFE  2   0   0    1   2  0    0   0   0     0   0   0   0    0   0
   ROB   0   1   0    0   1  2    0   0   0     0   0   0   0    0   0 
  </code></pre>
  
  <p>-Installed mysql2 gem for rails 2.3.8</p>
  
  <pre><code>gem install mysql2 -v0.2.6
  </code></pre>
  
  <p>-Created the controller:</p>
  
  <pre><code>class PolicyController &lt; ApplicationController
  
     def index
        @result =  ActiveRecord::Base.connection.execute("select distinct @sql := concat('SELECT pb.name as unit,',group_concat(concat('SUM(CASE WHEN p.state =0 AND ce.id=',id,' THEN 1 ELSE 0 END ) AS v',id,',SUM(CASE WHEN p.state =1 AND ce.id=',id,' THEN 1 ELSE 0 END ) AS a',id,',SUM(CASE WHEN p.state =2 AND ce.id=',id,' THEN 1 ELSE 0 END ) AS n',id)),' FROM cia_ensures ce LEFT JOIN policies p on ce.id = p.cia_ensure_id INNER JOIN policy_business_units pb ON pb.id = p.policy_business_unit_id  INNER JOIN comercial_areas ca ON ca.id = pb.comercial_area_id AND ca.id=1  Group by p.policy_business_unit_id') from cia_ensures where id in(1,2,3,4,5);")
        @result2 = ActiveRecord::Base.connection.execute("prepare stmt from @sql;")
        @result3 = ActiveRecord::Base.connection.execute("execute stmt;")
     end
  
  end
  </code></pre>
  
  <p>Here is the log:</p>
  
  <pre><code>SQL (0.9ms)   select distinct @sql := concat('SELECT pb.name as unit,',group_concat(concat('SUM(CASE WHEN p.state =0 AND ce.id=',id,' THEN 1 ELSE 0 END ) AS v',id,',SUM(CASE WHEN p.state =1 AND ce.id=',id,' THEN 1 ELSE 0 END ) AS a',id,',SUM(CASE WHEN p.state =2 AND ce.id=',id,' THEN 1 ELSE 0 END ) AS n',id)),' FROM cia_ensures ce LEFT JOIN policies p on ce.id = p.cia_ensure_id INNER JOIN policy_business_units pb ON pb.id = p.policy_business_unit_id INNER JOIN comercial_areas ca ON ca.id = pb.comercial_area_id AND ca.id=1 Group by p.policy_business_unit_id') from cia_ensures where id in(1,2,3,4,5);
  SQL (0.9ms)   prepare stmt from @sql;
  SQL (0.2ms)   execute stmt;
  </code></pre>
  
  <p>Here is the view (is working fine and without problems but seems to be too long write several times the same code)</p>
  
  <pre><code>&lt;table&gt;
    &lt;% @result3.each do |policy| %&gt;
    &lt;tr&gt;
        &lt;td&gt;&lt;%= policy[0] %&gt;&lt;/td&gt;
        &lt;td&gt;&lt;%= policy[1] %&gt;&lt;/td&gt;
        &lt;td&gt;&lt;%= policy[2] %&gt;&lt;/td&gt;
        &lt;td&gt;&lt;%= policy[3] %&gt;&lt;/td&gt;
        &lt;td&gt;&lt;%= policy[4] %&gt;&lt;/td&gt;
        &lt;td&gt;&lt;%= policy[5] %&gt;&lt;/td&gt;
        ...
    &lt;/tr&gt;
    &lt;%end%&gt; 
  &lt;/table&gt;
  </code></pre>
  
  <p>I tried to use inspect but it shows all the information in one td and not on each td:</p>
  
  <pre><code>&lt;% @result3.each do |policy| %&gt;
  &lt;tr&gt;      
   &lt;td align="center"&gt;&lt;%= policy.inspect %&gt;&lt;/td&gt;
  &lt;/tr&gt;
  &lt;%end%&gt; 
  </code></pre>
  
  <p>How can I do to show all this without writing lots of lines?</p>
  
  <p>Is it possible to make this in one line? without writing &lt;%= policy[#NUMBER] %></p>
  
  <p>Please somebody can help me with this?</p>
  
  <p>I will really appreciate it.</p>