ruby - Display array data in table using Rails 3 -


i want display array of data in table using rails 3. suppose have below array of data.

@vendor_type=["swd", "goods","swd"] 

my database structure given below.

table- payment_vendors: id  receipt_no   type   v_amount    v_date      c_date      v_name    v_status  7    150325005   swd     60.00     2015-04-15  2015-04-28   deepak    no  8    150325006   goods   1195.00   2015-04-15  2015-04-28   deepak    no 9    150325007   swd      60.00    2015-04-15  2015-04-29   deepak    no 

actually requirement when @vendor_type==swd,it retrieve receipt_no corresponding "swd".according receipt_no corresponding row data fetch , append in below table.

paymentdetails.html.erb:

<table class="table table-bordered">     <colgroup>         <col class="col-md-1 col-sm-1">         <col class="col-md-1 col-sm-1">         <col class="col-md-3 col-sm-3">         <col class="col-md-3 col-sm-3">         <col class="col-md-4 col-sm-4">     </colgroup>     <thead>         <tr>             <th class="text-center"><input type="checkbox"></th>             <th class="text-center">sl. no</th>             <th class="text-center">date</th>             <th class="text-center">receipt no.</th>             <th class="text-center">amount</th>         </tr>     </thead>     <tbody>         <tr>             <th class="text-center"><input type="checkbox" id="checkbox1-1" name="checkbox1-1"></th>             <td class="text-center"></td>             <td class="text-center"></td>             <td class="text-center"></td>             <td class="text-center"><i class="fa fa-rupee"></i></td>         </tr>     </tbody> </table> 

my controller file given below.

payments_controller.rb:

class paymentscontroller < applicationcontroller      def payment         @payment=vendor.new         respond_to |format|             format.html              format.js         end      end     def check_type           if params[:commit]=="submit"            @vendor_type=paymentvendor.where(:v_name => params[:v_name]).pluck(:type )            #@vendor_type=paymentvendor.pluck_all(paymentvendor.where(:v_name => params[:v_name]),:type ,:receipt_no)          else             @v_name=vendor.where(:s_catagory => params[:payment][:s_catagory] ).pluck(:v_name)         end     end end 

please me resolve issue.

i can give best guess @ want think trying ask this:

1) change line in check_type method in paymentscontroller:

@vendor_type=paymentvendor.where(:v_name => params[:v_name]) 

this gets rid of .pluck method , returns array of paymentvendor objects instead of column :type.

now in erb file need looping structure create rows in table body each item in @vendor_type data structure:

... </thead>   <tbody>    <% @vendor_type.each |vt| %>     <tr>         <td class="text-center"><input type="checkbox" id="checkbox1-1" name="checkbox1-1"></th>         <td class="text-center">????? column "sl. no" refer to??? </td>          <td class="text-center"><%= vt.v_date %></td>         <td class="text-center"><%= vt.receipt_no %></td>         <td class="text-center"><i class="fa fa-rupee"><%= vt.v_amount %></i></td>     </tr>    <% end %>   </tbody> </table>