在我的問題模型,我有一些範圍搬家will_paginate的模型
scope :recent, order("created_at DESC")
scope :approved, where("status = ?", "approved")
scope :answered, approved.recent.where("answers_count > ?", 0)
在我的問題控制器我使用的範圍
例如1檢索問題:
@questions = Question.approved.recent
例子2:
@questions = User.find(session[:user_id]).topics.map { |t| t.questions.approved.recent }.flatten.uniq
我正在試圖將will_paginate放在我的模型上,以使控制器上的操作變得更簡單,但第二個示例非常棘手,因爲它使用映射根據首選項檢索問題。
我試圖添加此對我的模型
def self.pagination(page = 1)
self.paginate(:page => page, :per_page => 5)
end
,然後我控制器上我有
@questions = Question.approved.recent.pagination.(params[:page])
,對於第一個例子正常工作,但我不知道如何實現在第二個例子
任何提示?