ruby - Collecting array of records from DB using Rails 3 -
i want access array of value db using different ids rails 3 got following error.
error:
nomethoderror in payments#download_pdf showing c:/site/swargadwara_puri1/app/views/payments/download_pdf.html.erb line #110 raised: undefined method `each' #<paymentvendor:0x329e9f8> extracted source (around line #110): 107: <td style="width:50%; border-right: 1px solid black;">item</td> 108: <td style="width:20%; text-align:right; border-right: 1px solid black;">amount</td> 109: </tr> 110: <% @pdf_vendor_details.each |details| %> 111: <% @count=@count+1 %> 112: <tr style="border: 1px solid black;"> 113: <td style="border-right: 1px solid black;"><%= @count %></td>
my other code files given below.
payments_controller.rb:
class paymentscontroller < applicationcontroller require "prawn/table" require "prawn" def payment @payment=vendor.new @add_payment=addpayment.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]).map{|v|[v.v_catagory ,v.receipt_no]} #@vendor_type = paymentvendor.where(:v_name => params[:v_name]).pluck(:v_catagory) @output=[] #@result=[] @r_no=[] @vendor_type.each |i| if i.first == params[:payment][:s_catagory] @output << i[1] end end @output.each |o| @r_no << o @result = paymentvendor.where(:receipt_no => @r_no,:v_catagory => params[:payment][:s_catagory],:v_name => params[:v_name],:v_status => "no" ) end #puts "#{val} => #{index}" #puts output1[index] #@result = paymentvendor.where(:receipt_no => @output[index],:v_catagory => params[:payment][:s_catagory],:v_name => params[:v_name] ) else @v_name=vendor.where(:s_catagory => params[:payment][:s_catagory] ).pluck(:v_name) end end def add_payment if params[:commit] #params[:details] == '1' ? remember : forget @userid=params[:deatils].collect{|id| id.to_i} if params[:deatils] #@userid=[] puts "id #{@userid}" @info=0 params[:infos].each |info| @info=@info+info.to_i end @total_amount=params[:deatils] @total=0 @count=0 @delet_id=[] params[:deatils].each |id| @delet_id << id @amount=paymentvendor.find(id) @total=@total+@amount.v_amount.to_i @count=@count+1 end if @total @outstanding= @info-@total if params[:add_payment][:p_catagory]=="cash" @add_payment=addpayment.create(:p_catagory => params[:add_payment][:p_catagory],:paid_amount => @total,:total_claim => @count,:outstanding => @outstanding ) if @add_payment @userid << @add_payment.id @delet_id.each |i| @del_id=paymentvendor.find(i) @del_id.update_attributes(:v_status => "yes") end @abc=true end end if params[:add_payment][:p_catagory]=="cheque" @add_payment=addpayment.create(:p_catagory => params[:add_payment][:p_catagory],:paid_amount => @total,:total_claim => @count,:chk_details => params[:chk_details],:chk_no => params[:chk_no],:outstanding => @outstanding ) @userid << @add_payment.id if @add_payment @delet_id.each |i| @del_id=paymentvendor.find(i) @del_id.update_attributes(:v_status => "yes") end @abc=true end end end else if params[:add_payment][:p_catagory]=="cheque" @chk=true else @cash=true end end end def download_pdf @all_userid=params[:all_id] #puts "all ids #{@all_userid}" #puts "rest ids #{@all_userid-[@all_userid.last]}" @rest_ids=@all_userid-[@all_userid.last] @pdf_payment_result=addpayment.find(@all_userid.last) @rest_ids.each |ids| @count=0 @pdf_vendor_details = paymentvendor.find(ids) end puts "pdf vendor details #{@pdf_vendor_details}" @pdf_address=vendor.where(:v_name => @pdf_vendor_details.v_name , :s_catagory => @pdf_vendor_details.v_catagory ).pluck(:v_address) @pdf_name=" #{time.now.strftime("%d%m%y%h%m%s") + '_' + @pdf_vendor_details.v_name + '_' + @pdf_vendor_details.v_catagory}.pdf " pdf = render_to_string(pdf: "test.pdf", template: "payments/download_pdf.html.erb", encoding: "utf-8", layout: 'application') send_data pdf ,:disposition => 'inline', filename: 'something.pdf', :type => 'application/pdf',:page_height => 'a2' save_path = rails.root.join('pdfs', @pdf_name) file.open(save_path, 'wb') |file| file << pdf end end end
download_pdf.html.erb:
<div class="modal-content"> <div class="modal-header"> <h4 class="modal-title" id="mymodallabel">payment advice</h4> </div> <div class="modal-body"> <div class="bgcolorwhite"> <table class="table"> <tr> <th style="width: 50%; text-align:left;"> <div class="pull-left"><%= wicked_pdf_image_tag 'odishalogo.png',:border => "0",:name => "odishagovtlogo",:style => "width:60px; height:60px;" %></div> <div class="pull-left" style="padding:14px 0px 0px 10px;">swargadwar, puri municipality <br /> government of odisha</div> <div class="clearfix"></div> </th> <th style="width:20%;"></th> <th style="width: 30%; text-align:left; vertical-align: top;">date : <%= date.today.to_s %><br /> bill no.: <%= rand(10000) %> </th> </tr> <tr> <td colspan="3"> <strong>vendor name</strong> :<%= @pdf_vendor_details.v_name %><br> <strong>address</strong> : <%= @pdf_address %> </td> </tr> <tr> <td colspan="3"> <table style="border: 1px solid #000000; width:100%;"> <tr style="border: 1px solid #000000; background-color:#7878c3; color:#fff;"> <td style="width:10%; border-right: 1px solid #000000;">sl. no</td> <td style="width:20%; border-right: 1px solid black;">receipt no</td> <td style="width:50%; border-right: 1px solid black;">item</td> <td style="width:20%; text-align:right; border-right: 1px solid black;">amount</td> </tr> <% @pdf_vendor_details.each |details| %> <% @count=@count+1 %> <tr style="border: 1px solid black;"> <td style="border-right: 1px solid black;"><%= @count %></td> <td style="border-right: 1px solid black;"><%= details.receipt_no %></td> <td style="border-right: 1px solid black;"><%= details.v_catagory %></td> <td style="text-align:right; border-right: 1px solid black;"><i class="fa fa-rupee"></i><%= details.v_amount %></td> </tr> <% end %> <tr> <td colspan="2" style="vertical-align: top;"><strong>note :</strong>thanks business<br /> <% if @pdf_payment_result.p_catagory== 'cash' %> <strong>payment mode :</strong><%= @pdf_payment_result.p_catagory %><br /> <% end %> <% if @pdf_payment_result.p_catagory== 'cheque' %> <strong>payment mode :</strong><%= @pdf_payment_result.p_catagory %><br /> <strong>cheque no :</strong> <%= @pdf_payment_result.chk_no %>, <%= @pdf_payment_result.chk_details %> <% end %> </td> <td style="text-align: right;">total :<br /> paid :<br /> outstanding :<br /> due payment :<br /> gross total : </td> <td style="text-align: right;"><i class="fa fa-rupee"></i> <%= @pdf_payment_result.paid_amount.to_s.to_d + @pdf_payment_result.outstanding.to_s.to_d %><br /><i class="fa fa-rupee"></i><%= @pdf_payment_result.paid_amount %><br /><i class="fa fa-rupee"></i> <%= @pdf_payment_result.outstanding %><br /><i class="fa fa-rupee"></i> 120<br /><i class="fa fa-rupee"></i> 920</td> </tr> </table> </td> </tr> <tr> <td style="text-align:center;"> <div style="height:70px;"> </div><br /> <span style="border-top:1px solid #000;">puri municipality</span> </td> <td></td> <td style="text-align:center;"> <div style="height:70px;"> </div><br /> <span style="border-top:1px solid #000;">paid by</span> </td> </tr> </table> </div> </div> </div>
total_paymentdetails.html.erb:
<table class="table table-bordered"> <colgroup> <col class="col-md-1 col-sm-1"> <col class="col-md-3 col-sm-3"> <col class="col-md-2 col-sm-2"> <col class="col-md-2 col-sm-2"> <col class="col-md-2 col-sm-2"> <col class="col-md-2 col-sm-2"> </colgroup> <thead> <tr> <th class="text-center">sl. no</th> <th class="text-center">date</th> <th class="text-center">total claim</th> <th class="text-center">paid</th> <th class="text-center">outstanding</th> <th class="text-center">payment advice</th> </tr> </thead> <tbody> <tr> <td class="text-center">1</td> <td class="text-center"><%= @add_payment.created_at %></td> <td class="text-center"><%= @add_payment.total_claim %></td> <td class="text-center"><i class="fa fa-rupee"></i><%= @add_payment.paid_amount %></td> <td class="text-center"><i class="fa fa-rupee"></i><%= @outstanding %></td> <td class="text-center"> <div class="btn-group"> <%= link_to "download pdf",payments_path(:format => "pdf",all_id: @userid ),:target => "_blank",method: :put %> </div> <div class="btn-group"> <a href="javascript:void(0)" title="" class="btn btn-xs btn-danger"> <i class="fa fa-download"></i> </a> </div> </td> </tr> </tbody> </table>
please check download_pdf
method,here @pdf_vendor_details
variable should contain array of records using different ids.but not happening that.please me resolve error.
try this:
<%= link_to "download pdf",payments_path(:format => "pdf",:all_id => @userid.to_s),:target => "_blank",method: :put %>
Comments
Post a Comment