Ruby on rails 按向上投票的方式进行可投票排序
到目前为止,我还没有找到任何能够通过使用 以下是我的投票和索引方法:Ruby on rails 按向上投票的方式进行可投票排序,ruby-on-rails,rubygems,Ruby On Rails,Rubygems,到目前为止,我还没有找到任何能够通过使用 以下是我的投票和索引方法: def upvote @question = Question.find params[:id] @question.liked_by current_user redirect_to comment_questions_path end def index @comment = Comment.find params[:comment_id] @questions = @comment.questio
def upvote
@question = Question.find params[:id]
@question.liked_by current_user
redirect_to comment_questions_path
end
def index
@comment = Comment.find params[:comment_id]
@questions = @comment.questions
end
我的问题是:
<%= div_for(question) do %>
<% if question.votes.size > 0 %>
<div class="verifiedanswer">
<%= question.body %>
</div>
<% else %>
<div class="answercontainer2">
<%= question.body %>
</div>
<% end %>
0 %>
我应该在视图和控制器中放置什么才能使其工作?这个特定的gem有一个缓存迁移,您也可以运行 类AddCachedVotesToPosts
<% Post.order(:cached_votes_up).each do |post| %>
... html goodness here ...
<% end %>
... 我的天啊。。。
这将根据投票数进行排序。对不起,rails是新手,我不确定如何在我看来实现这一点。添加了更多。你知道如何在计票或按日期加权时只包括最近的选票吗?试图实现一个排序方式:“hot”,我个人更喜欢
Post.order(:cached\u voces\u score)。反转,这将考虑到任何下行投票。
<% Post.order(:cached_votes_up).each do |post| %>
... html goodness here ...
<% end %>