Quantcast
Channel: Active questions tagged ruby - Stack Overflow
Viewing all articles
Browse latest Browse all 4609

Display button for each index

$
0
0

I have to show barcode button for unpaid payments.Am looping the unpaid payments but still two barcodes are displayed for one payment.Here is the code snippet.I have two table payments and payment records both of them are connected through foreign key payment_id.Each payment has payment records.The payment records table consist of field called barcode url.Now I want to display the corresponding barcode_url for each paymentWhat should I do ? Current it displays all the barcode buttons to a paymentSomebody please help !.

Controller method is described below

def payments @paid_payments = current_user.get_valid_paid_payments.order(created_at: :desc).paginate(page: params[:page], per_page: 5)    @unpaid_payments = current_user.get_valid_unpaid_payments.order(created_at: :desc)    payment_records = PaymentRecord.where(payment_id: @unpaid_payments.pluck(:id))    @barcode_data = payment_records.each_with_object({}) do |record, hash|      hash[record.payment_id] = record.barcode_url    end`your text`    @smartpit = current_user.smartpits.take    @user = current_user    render :layout => 'mypage'end

View file

<div class="container"><div class="vertical-center center-barcode"><% @unpaid_payments.each do |payment| %><% barcode_url = @barcode_data[payment.id] %><% if barcode_url.present? %><a href="<%= barcode_url %>" class="btn btn-danger" target="_blank"><%= t 'users.bill_detail.new_payment_method_barcode' %></a><% end %><% end %></div></div>

Viewing all articles
Browse latest Browse all 4609

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>