Hi Guys,
In my application I created this method:

def self.find_paginated_posts_by_post_type(post_type,page=1,query="")
if query.empty? == false
query = “%#{query}%”
query = “%”
result = includes(:user).
where([‘post_type_id = ? AND title LIKE ?’, post_type.id,
order(‘created_at DESC’).
return result

this method is returning an ActiveRecord::Relation Object. So, when I
will_paginate method my application throws an exception :

undefined method `total_pages’ for

How can I fix it?

Bruno M.

On Feb 9, 2012, at 5:11 PM, Bruno M. wrote:

         where(['post_type_id = ? AND title LIKE ?', post_type.id, query]).

How can I fix it?

If you add to_a to the end of the request, before you pass it to
paginate, then all of the results will be queried and returned as an
array – old-school. But if you use Kaminari or another pagination
system that works natively with ActiveRecord::Relation objects, you
won’t have this issue (and you will get the benefits of Arel and all the
wonder that is Rails 3+).


Hi Walter,
I will take a look in this solution and in this Kamirami
Thx for the answer ;D

First time using Kaminari… But it seems to be a good gem.
Thx for the tip ;D

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs