简体   繁体   English

印象派瑰宝-按视图对帖子排序

[英]Impressionist gem - sort posts by views

I'm using the following gem and now I'm trying to sort posts by the number of views. 我正在使用以下gem ,现在尝试按视图数对帖子进行排序。

I have followed the instructions and in my post model, so I have: 我已经按照说明进行操作,并且在我的帖子模型中,所以有:

is_impressionable :counter_cache => true

And in my controller, I have: 在我的控制器中,我有:

@mostpopular = @posts.order('counter_cache DESC').limit(6)

But I'm getting an error: 但是我遇到一个错误:

SQLite3::SQLException: no such column: counter_cache: SELECT "posts".* FROM "posts" ORDER BY counter_cache DESC LIMIT 6 SQLite3 :: SQLException:没有这样的列:counter_cache:SELECT“ posts”。* FROM“ posts” ORDER BY counter_cache DESC LIMIT 6

Did you added field to your model? 您是否在模型中添加了字段?

is_impressionable :counter_cache => true

This will automatically increment the impressions_count column in the included model. 这将自动增加所包含模型中的impressions_count列。 Note: You'll need to add that column to your model. 注意: 您需要将该列添加到模型中。

To add you can do: 要添加,您可以执行以下操作:

t.integer :my_column_name, :default => 0

Read about this moment 了解这一刻

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

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