Let's say we have @posts = Post.published.per(10).page(params[:page])
somewhere in our controller. Later on we need to update all published posts (Post.published
).
How should one remove the pagination?
@posts.limit(false).offset(false)
seems to do the trick but I think there should be some other way, a more high-level way (something like @posts.without_pagination
).
As the page
method is provided by kaminari, I do not sure if kaminari provide also something like without_pagination
.
But if you like, you could always do this:
class Post < ActiveRecord::Base
def self.without_pagination
self.limit(false).offset(false)
end
end
or you could extract the method out to a module and include the module into ActiveRecord::Base so that every model has the method.
Thank you tfwright for pointing out. Could use .except(:limit, :offset)
which should be much better for later comers.
@posts = Post.publised.per(10).page(params[:page])
@posts = @posts.except(:limit, :offset)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With