私のアプリケーションでは、多くの支払いと請求書を持つ顧客モデルがあります。顧客にRailsはクエリー結果を組み合わせたwill_paginateを使用します
# 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
私はすべての請求書と支払を組み合わせ、@transactionsインスタンス変数に格納していたテンプレートを示しています。
class CustomersController < ApplicationController
def show
@customer = Customer.find(params[:id])
payments = Payment.where(customer: @customer)
invoices = Invoice.where(customer: @customer)
@transactions = payments + invoices
end
will_paginateを使用して@トランザクションにページを設定したいとします。これを行うと機能しません:
@transactions.paginate(page: params[:page])
これを実行するにはどうすればよいでしょうか?
この回答はあなたの問題を解決しますhttp://stackoverflow.com/questions/4352895/ruby-on-rails-will-paginate-an-array – Thorin