title: render all records in a stored procedure
body: <p>I am trying to render all the data of a stored procedure in a table in my view but the problem is that the name of the columns can change in each stored query so I can not make the specific field call in the render because each query brings different columns, how could I make the call of the columns name for the  (table titles) and render all the data in the  unspecified in the name of the data but bring all the results of the query that apparently returns them in an array?</p>
  
  <p>this is my stored_procedures_controller.rb</p>
  
  <pre><code>class StoredProceduresController &lt; ApplicationController
    before_action :authenticate_usuario!
  
  
    def cantidad_productosxpedido
      @cantidad_productosxpedido = Stored_procedure.fetch_db_records("exec SPAD_ReporteProductosxPedido '#{Time.now.try(:strftime,"%Y%m%d")}','#{params[:search]}','#{params[:search6]}'")
      respond_to do |format|
        format.html
        format.js
        format.xls
      end
    end
  
  end
  </code></pre>
  
  <p>this is my model stored_procedure.rb</p>
  
  <pre><code>class Stored_procedure &lt; ActiveRecord::Base
  
    def self.fetch_db_records(proc_name_with_parameters)
      connection.select_all(proc_name_with_parameters)
    end
  
    def self.insert_update_delete_calculate(proc_name_with_parameters)
      connection.execute(proc_name_with_parameters)
    end
  
    def self.fetch_val_from_sp(proc_name_with_parameters)
      connection.select_value(proc_name_with_parameters)
    end
  
  end
  </code></pre>
  
  <p>I usually do the rendering of the stored this way</p>
  
  <pre><code>&lt;table class="table table-striped table-bordered table-condensed table-hover rwd_auto"&gt;
      &lt;thead&gt;
        &lt;tr&gt;
          &lt;th&gt;Ruta&lt;/th&gt;
          &lt;th&gt;Pedido&lt;/th&gt;
          &lt;th&gt;IdCliente&lt;/th&gt;
          &lt;th&gt;Cliente&lt;/th&gt;
          &lt;th&gt;Nombre Comercial&lt;/th&gt;
          &lt;th&gt;2010100&lt;/th&gt;
          &lt;th&gt;2020100&lt;/th&gt;
          &lt;th&gt;2020200&lt;/th&gt;
          &lt;th&gt;2020500&lt;/th&gt;
          &lt;th&gt;2021200&lt;/th&gt;
          &lt;th&gt;2200500&lt;/th&gt;
          &lt;th&gt;2200501&lt;/th&gt;
          &lt;th&gt;2200508&lt;/th&gt;
          &lt;th&gt;2200509&lt;/th&gt;
          &lt;th&gt;2201000&lt;/th&gt;
          &lt;th&gt;2203100&lt;/th&gt;
          &lt;th&gt;2203101&lt;/th&gt;
          &lt;th&gt;2203102&lt;/th&gt;
          &lt;th&gt;2203104&lt;/th&gt;
          &lt;th&gt;2203108&lt;/th&gt;
          &lt;th&gt;2203200&lt;/th&gt;
        &lt;/tr&gt;
     &lt;/thead&gt;
    &lt;tbody id="container_productosxpedido"&gt;
      &lt;%= render partial: "/stored_procedures/cantidad_productoxpedido", collection: @cantidad_productosxpedido %&gt;
    &lt;/tbody&gt;
  &lt;/table&gt;
  </code></pre>
  
  <p>and in the partial _cantidad_productoxpedido</p>
  
  <pre><code>&lt;tr&gt;
    &lt;td&gt;&lt;%= cantidad_productoxpedido['Ruta'] %&gt;&lt;/td&gt;
    &lt;td&gt;&lt;%= cantidad_productoxpedido['Pedido'] %&gt;&lt;/td&gt;
    &lt;td&gt;&lt;%= cantidad_productoxpedido['IdCliente'] %&gt;&lt;/td&gt;
    &lt;td&gt;&lt;%= cantidad_productoxpedido['Cliente'] %&gt;&lt;/td&gt;
    &lt;td&gt;&lt;%= cantidad_productoxpedido['NombreCorto'] %&gt;&lt;/td&gt;
    &lt;td&gt;&lt;%= cantidad_productoxpedido['2010100'] %&gt;&lt;/td&gt;
    &lt;td&gt;&lt;%= cantidad_productoxpedido['2020100'] %&gt;&lt;/td&gt;
    &lt;td&gt;&lt;%= cantidad_productoxpedido['2020200'] %&gt;&lt;/td&gt;
    &lt;td&gt;&lt;%= cantidad_productoxpedido['2020500'] %&gt;&lt;/td&gt;
    &lt;td&gt;&lt;%= cantidad_productoxpedido['2021200'] %&gt;&lt;/td&gt;
    &lt;td&gt;&lt;%= cantidad_productoxpedido['2200500'] %&gt;&lt;/td&gt;
    &lt;td&gt;&lt;%= cantidad_productoxpedido['2200501'] %&gt;&lt;/td&gt;
    &lt;td&gt;&lt;%= cantidad_productoxpedido['2200508'] %&gt;&lt;/td&gt;
    &lt;td&gt;&lt;%= cantidad_productoxpedido['2200509'] %&gt;&lt;/td&gt;
    &lt;td&gt;&lt;%= cantidad_productoxpedido['2201000'] %&gt;&lt;/td&gt;
    &lt;td&gt;&lt;%= cantidad_productoxpedido['2203100'] %&gt;&lt;/td&gt;
    &lt;td&gt;&lt;%= cantidad_productoxpedido['2203101'] %&gt;&lt;/td&gt;
    &lt;td&gt;&lt;%= cantidad_productoxpedido['2203102'] %&gt;&lt;/td&gt;
    &lt;td&gt;&lt;%= cantidad_productoxpedido['2203104'] %&gt;&lt;/td&gt;
    &lt;td&gt;&lt;%= cantidad_productoxpedido['2203108'] %&gt;&lt;/td&gt;
    &lt;td&gt;&lt;%= cantidad_productoxpedido['2203200'] %&gt;&lt;/td&gt;
  &lt;/tr&gt;
  </code></pre>
  
  <p>but when changing the name of the columns I do not know how to do to display the data without specifying the names of those columns</p>
  
  <p>UPDATE </p>
  
  <p>I could resolve to display the contents of the table as follows</p>
  
  <pre><code>  &lt;%@cantidad_productosxpedido.to_a.each do |foo|%&gt;
            &lt;tr&gt;
              &lt;%foo.each do |label, value|%&gt;
                &lt;td&gt;&lt;%= value %&gt;&lt;/td&gt;
              &lt;%end%&gt;
            &lt;/tr&gt;
          &lt;%end%&gt;
  </code></pre>
  
  <p>but now I try to add the headers of the table 
  like this:</p>
  
  <pre><code>  &lt;%@cantidad_productosxpedido.first.each do |foo|%&gt;
        &lt;tr&gt;
          &lt;%foo.each do |label, value|%&gt;
            &lt;th&gt;&lt;%= label %&gt;&lt;/th&gt;
          &lt;%end%&gt;
        &lt;/tr&gt;
    &lt;%end%&gt;
  </code></pre>
  
  <p>but it does not show correct in the table  but renders it as follows</p>
  
  <pre><code>&lt;tr&gt;
       &lt;th&gt;title1&lt;/th&gt; &lt;td&gt;value1&lt;/th&gt;
  &lt;/tr&gt;
  &lt;tr&gt;
        &lt;th&gt;title2&lt;/th&gt; &lt;th&gt;value2&lt;/th&gt;
  &lt;/tr&gt;
  </code></pre>