Reputation: 45
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.
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)
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. 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?
Upvotes: 1
Views: 720
Reputation: 4417
According to the Impressionable docs, you can add a counter cache to your model. This looks like the best way to achieve this.
Upvotes: 3