def self.find_paginated_posts_by_post_type(post_type,page=1,query="")
if query.empty? == false
query = “%#{query}%”
else
query = “%”
end
result = includes(:user).
where([‘post_type_id = ? AND title LIKE ?’, post_type.id,
query]).
order(‘created_at DESC’).
page(page)
return result
end
this method is returning an ActiveRecord::Relation Object. So, when I
use
will_paginate method my application throws an exception :
where(['post_type_id = ? AND title LIKE ?', post_type.id, query]).
How can I fix it?
Thx
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+).