按票数对帖子进行排序
大家好,老读者,第一次发帖:)
我有一个包含帖子的应用程序,我正在使用 gemthums_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'
})
end
和耻辱之墙:
def wall_of_fame
@posts = Post.tally(
{ :at_least => 1,
:at_most => 10000,
:limit => 10,
:order => 'vote_count asc'
})
end
但实际上我需要使用 plusminus 方法来排序帖子,而不仅仅是 vote_count ,因为它只是显示我写了一些帖子,而不是得票最多的帖子,或者至少是这样的:
:order => 'votes_for asc'
对于 wall_of_shame
:order => 'votes_against asc'
目前 votes_for 和 votes_against 只能在视图中使用,例如
@post.votes_for
如何在我的帖子控制器中使用它们才能使用它们在 :order => 中?
谢谢。
Hi everybody long time reader, first time poster :)
I have an app with posts and I am using the gem thumbs_up ( rails v. 3.0.7) to add votes to the posts. I have implemented a wall of fame for the posts showing the top 10 posts and I just can't figure out how to sort the posts by votes ( plusminus method).
Now I am just using:
def wall_of_fame
@posts = Post.tally(
{ :at_least => 1,
:at_most => 10000,
:limit => 10,
:order => 'vote_count desc'
})
end
and for the wall of shame:
def wall_of_fame
@posts = Post.tally(
{ :at_least => 1,
:at_most => 10000,
:limit => 10,
:order => 'vote_count asc'
})
end
but actually I need to order the posts using the plusminus method and not just vote_count, because it just shows me some posts, not the ones with the most up votes, or at least something like:
:order => 'votes_for asc'
and for the wall_of_shame
:order => 'votes_against asc'
Currently votes_for and votes_against can be used only in the views like
@post.votes_for
How can I use them in my posts controller to be able to use them in :order => ?
Thank you.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我也面临这个问题,但我从头开始构建了我的投票机制。我最终在视图中对我的帖子进行了排序。所以,我像这样重新排列它们:
这将我的帖子从得票最多到最少得票排序。
祝你好运!
@thatdankent
I faced this issue as well, but I built my voting machinery from scratch. I ended up sorting my posts in the views. So, I redered them like this:
This ordered my posts from the most votes to the least votes.
Good Luck!
@thatdankent
您只需订购 plusminus:
http://gistpages.com/2013/08/28/order_by_votes_using_the_thumbs_up_gem< /a>
You just need to order plusminus:
http://gistpages.com/2013/08/28/order_by_votes_using_the_thumbs_up_gem