简体   繁体   English

Rails Impressionist Gem - WillPaginate :: Collection不易受影响

[英]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: 我尝试将印象派用于这样的will_paginate集合:

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? 有没有办法直接在视图上使用印象派方法?

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. will_paginate生成的集合不易受影响,意味着您正在阅读,它的类没有任何对is_impressionable调用,因为您的模型应该具有。 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. Impressionist会创建一个数据库记录,这会减慢视图渲染速度。 It will be better to do it in the model or controller layers. 最好在模型或控制器层中执行此操作。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM