我正在实现activerecord-reputation-system gem,但在处理最受欢迎的文章时遇到了问题。
/articles_controller
def index
....
@loved_articles = Article.page(params[:page]).find_with_reputation(:votes, :all, {:order => 'votes DESC, created_at DESC'})
....
end我尝试在:page) .per(5) ....之后调用.per(5)。但是rails给了我一个"undefined method ` `per'“错误
/article model
def self.loved
find_with_reputation(:votes, :all, {:order => 'votes DESC'}).first(5)
end-
我会想象调用.first(5)会将其作用域,但什么都没有发生-在我看来,这个循环只是在蚕食我所有的文章。有什么想法吗?
发布于 2012-12-07 09:51:36
不要紧-我没有使用分页...
在我的控制器中添加了@loved_articles = Article.loved
发布于 2012-12-07 09:54:20
这样写怎么样?
Article.find_with_reputation(:votes, :all, {:order => 'votes DESC, created_at DESC'}).per(5)
https://stackoverflow.com/questions/13755708
复制相似问题