In my application I have a customers model that has many payments and invoices.
# customer.rb
class Customer < ActiveRecord::Base
has_many :payments
has_many :invoices
end
# payment.rb
class Payment < ActiveRecord::Base
belongs_to :customer
end
# invoice.rb
class Invoice < ActiveRecord::Base
belongs_to :customer
end
In the customers show template I am combining all Invoices and Payments and storing them in the @transactions instance variable.
class CustomersController < ApplicationController
def show
@customer = Customer.find(params[:id])
payments = Payment.where(customer: @customer)
invoices = Invoice.where(customer: @customer)
@transactions = payments + invoices
end
I want to paginate @transactions using will_paginate. Doing this doesn't work:
@transactions.paginate(page: params[:page])
What is the best way to accomplish this?