如何获得投票超过一定数量的帖子? - Rails

How to get posts with votes above a certain number? - Rails

我正在尝试制作一个供稿页面,用户可以在其中查看热门帖子和他们关注的帖子。这是我尝试过的(但失败了):

  @popularPosts = Post.where(cached_votes_score > '2')

返回错误。

undefined local variable or method `cached_votes_score' for #<PagesController:0x007fa2ae08f630> Did you mean? cache_store

有什么想法吗?

你想要的已经完成:

Post.where('cached_votes_score > 2')

您尝试执行的操作被解释为尝试调用控制器中的方法 cached_votes_score 并比较其返回值是否大于 '2'

Rails 没有 Railsism 做大于比较,所以你做一个 SQL 部分来完成它.