9

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?

ErvalhouS
  • 4,178
  • 1
  • 22
  • 38
Mr McDonald
  • 453
  • 7
  • 16
  • What did you try so far? Please share your code. What was the issue? – spickermann Apr 07 '18 at 05:52
  • Hello spickermann, thank you very much for your answer. I paginate a result like this: posts = Post.all.paginate(:page => params[:page]) and then I try to use impressionist gem on posts with the method: impressionist(posts) but I get this error: WillPaginate::Collection is not impressionable! How can I use impressionst gem with a WillPaginate:Collection? Thank you for you help. – Mr McDonald Apr 07 '18 at 21:41

1 Answers1

2

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.

ErvalhouS
  • 4,178
  • 1
  • 22
  • 38