【问题标题】:Impressionist gem - sort posts by views印象派宝石 - 按视图排序帖子
【发布时间】:2016-07-06 15:57:17
【问题描述】:

我正在使用以下gem,现在我正在尝试按观看次数对帖子进行排序。

我已按照说明在我的帖子模型中进行操作,所以我有:

is_impressionable :counter_cache => true

在我的控制器中,我有:

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

但我收到一个错误:

SQLite3::SQLException: 没有这样的列:counter_cache: SELECT "posts".* FROM "posts" ORDER BY counter_cache DESC LIMIT 6

【问题讨论】:

    标签: ruby-on-rails ruby impressionist


    【解决方案1】:

    您是否在模型中添加了字段?

    is_impressionable :counter_cache => true
    

    这将自动增加 包括模型。注意:您需要将该列添加到您的模型中。

    添加你可以这样做:

    t.integer :my_column_name, :default => 0
    

    Read about this moment

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-03-06
      • 1970-01-01
      • 2015-07-16
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多