大家好,长期读者,第一次海报:)
我有一个带有帖子的应用程序,我正在使用 gem thumbs_up ( rails v. 3.0.7) 为帖子添加投票。我已经为显示前 10 个帖子的帖子设置了名人墙,但我只是不知道如何按投票对帖子进行排序(加减法)。
现在我只是在使用:
def wall_of_fame
@posts = Post.tally(
{ :at_least => 1,
:at_most => 10000,
:limit => 10,
:order => 'vote_count desc'
})
结尾
和耻辱之墙:
def wall_of_fame
@posts = Post.tally(
{ :at_least => 1,
:at_most => 10000,
:limit => 10,
:order => 'vote_count asc'
})
结尾
但实际上我需要使用plusminus方法而不只是vote_count来排序帖子,因为它只是向我显示一些帖子,而不是投票最多的帖子,或者至少是类似的:
:order => 'votes_for asc'
并为 wall_of_shame
:order => 'votes_against asc'
目前 votes_for 和 votes_against 只能在视图中使用
@post.votes_for
如何在我的帖子控制器中使用它们以便能够在:order =>中使用它们 ?
谢谢你。