简体   繁体   English

按照Rails中的impressionist gem制作的view_count对条目进行排序

[英]Sort entries by view_count made from impressionist gem in Rails

I'm having a small problem with my code here. 我的代码在这里遇到了一个小问题。 Not as much a problem as it's just me that doesn't know how to accomplish this. 没有那么多问题,只有我不知道如何实现这一目标。 I'm still new in the rails world. 我还是铁杆世界的新人。 So figured i would ask here before i made a bad McGyver solution. 因此,在我做出糟糕的McGyver解决方案之前,我会问这里。

Anyway, i'm using the Impressionist gem to handle all of my view counts on the various photo entries i have in my database (MySQL) 无论如何,我正在使用Impressionist gem处理我在数据库(MySQL)中的各种照片条目上的所有视图计数

And i was just wondering if anyone has a good method on how to sort all entries in my database by their view count. 我只是想知道是否有人有一个很好的方法来如何按他们的视图计数对我的数据库中的所有条目进行排序。 The way i see it, i have to compare the amount of impressionable_id's with the id's of their respected entry. 我看到它的方式,我必须比较impressionable_id的数量与他们尊重的条目的id。 However, i'm unsure as to how to go about this. 但是,我不确定如何解决这个问题。

I just want my photo controller index method to spew out every photo entry it has, but sort it by the amount of views the entries have in the impressions table. 我只是希望我的照片控制器索引方法能够显示它所拥有的每个照片条目,但是根据条目在印象表中的视图数量进行排序。

Any ideas? 有任何想法吗?

According to the Impressionable docs, you can add a counter cache to your model. 根据Impressionable文档,您可以为模型添加计数器缓存 This looks like the best way to achieve this. 这看起来是实现这一目标的最佳方式。

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

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