2012-12-07 42 views
0

我正在實施activerecord-reputation-system gem,並且遇到了一個面向最受歡迎的文章的問題。Rails主動記錄聲望系統範圍/查詢問題

/articles_controller 
def index 
    .... 
    @loved_articles = Article.page(params[:page]).find_with_reputation(:votes, :all, {:order => 'votes DESC, created_at DESC'}) 
    .... 
end 

我打過電話.per(5)後的[:頁面])每(5)....但導軌給了我錯誤

/article model 

def self.loved 
    find_with_reputation(:votes, :all, {:order => 'votes DESC'}).first(5) 
end 

的 「每」未定義的方法`「。 -

我會想象調用.first(5)可以調用它,但沒有任何事情發生 - 在我看來,循環只是咀嚼所有的文章。有任何想法嗎?

+0

寫沒關係 - 我不使用分頁... – cpursley

回答

0

沒關係 - 我不使用分頁...

新增@loved_articles = Article.loved在我的控制器

1

這個怎麼樣

Article.find_with_reputation(:votes, :all, {:order => 'votes DESC, created_at DESC'}).per(5)