Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Rails Impressionist Gem - WillPaginate::Collection is not impressionable

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?

like image 396
rod Avatar asked Apr 03 '18 20:04

rod


1 Answers

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.

like image 170
ErvalhouS Avatar answered Oct 13 '22 01:10

ErvalhouS