2011-10-24 74 views
2

假设我们有我们的控制器中的某个地方有@posts = Post.published.per(10).page(params[:page])。稍后我们需要更新所有发布的帖子(Post.published)。有没有办法从ActiveRelation对象中移除分页?

应该怎么去除分页?

@posts.limit(false).offset(false)似乎在做的伎俩,但我认为应该有一些其他方式,更高层次的方式(如@posts.without_pagination)。

回答

5

由于kaminari提供了page方法,我不确定kaminari是否也提供类似without_pagination的东西。

但如果你喜欢,你总是可以做到这一点:

class Post < ActiveRecord::Base 
    def self.without_pagination 
    self.limit(false).offset(false) 
    end 
end 

,或者你可以提取方法出一个模块,包括模块插入的ActiveRecord :: Base的让每一个模型的方法。

相关问题