I using this instance to find more view 5 Item, but cannot get the result.
Can teach me how to get it?
@test = Item.limit(5).joins(:impressions).group("impressions.impressionable_id").order("count(impressions.impressionable_id) DESC")
You can achieve the using counter cache. In this approach you've to create a new column to your model
and add some configuration to your model. Thus, the gem will automatically update the view count.
Or, (not tested, but should work)
Item.joins(:impressions).group("impressions.impressionable_id").order("count(impressions.id) DESC").first(5)