Rails Impressionist Gem - WillPaginate::Collection is not impressionable

252 Views Asked by At

There is any way to use impressionist gem with will paginate? I try to use impressionist to a will_paginate collection like this:

posts = Post.all.paginate(:page => params[:page]) 
impressionist(posts) 

But It raises this error:

WillPaginate::Collection is not impressionable!

There is any way to use impressionist method directly on view?

1

There are 1 best solutions below

0
On

The collection generated by will_paginate is not impressionable means exactly you are reading, it's class doesn't have any calls to is_impressionable, as your model should have. If it doesn't, add it like this:

class Post < ActiveRecord::Base
    # ...other stuff
    is_impressionable
end

Then, if you can't call it in the collection, why not call it in each record instead? Try like this:

posts = Post.all.paginate(:page => params[:page])
posts.each{|post| impressionist(post) }

Maybe it's not the most elegant solution, but it will get the work done. As of doing this in your view, I wouldn't advise it. Impressionist creates a database record, which would slow your view rendering. It will be better to do it in the model or controller layers.