2016-07-06 86 views
0

我使用以下gem,现在我试图根据视图数量对帖子进行排序。印象派宝石 - 按意见排序帖子

我按照说明书,在我的岗位模型,所以我有:

is_impressionable :counter_cache => true 

而在我的控制,我有:

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

但我发现了一个错误:

SQLite3::SQLException: no such column: counter_cache: SELECT "posts".* FROM "posts" ORDER BY counter_cache DESC LIMIT 6

回答

0

您是否已将字段添加到模型中?

is_impressionable :counter_cache => true 

This will automatically increment the impressions_count column in the included model. Note: You'll need to add that column to your model.

要添加,你可以这样做:

t.integer :my_column_name, :default => 0 

Read about this moment