我通常知道您可以使用这样的分页:
class SearchController < ApplicationController
def index
@search = Product.search do
fulltext params[:search]
paginate(:page => 1, :per_page => 5)
end
@products = @search.results
end
end
但是像这样更复杂的事情呢?
class SearchController < ApplicationController
def index
@search = Product.search do
fulltext params[:search]
#This line will be for me to have an association because Products has_many Prices
@prices = Price.joins(:product).where(:product_id => [1,2,3]).paginate(:page => params[:page])
end
@products = @search.results
end
end
我还没有找到关于太阳黑子的分页或任何深度教程的文档。是否可以正常使用will_paginate?
答案 0 :(得分:2)
paginate是否适用于任何数组对象。
搜索返回并且数组正确吗?所以你可以这样做:
search = Product.search do
fulltext params[:search]
end
@search = search.paginate(:page => params[:page], :per_page => params[:rows])