order comments by the most recent first

This commit is contained in:
David Gil
2015-08-11 20:27:37 +02:00
parent 9d2bece0b3
commit 44d4fa9fc4
5 changed files with 11 additions and 9 deletions

View File

@@ -4,11 +4,11 @@ class DebatesController < ApplicationController
def index
if params[:tag]
@debates = Debate.tagged_with(params[:tag]).order("created_at DESC")
set_voted_values @debates.map(&:id)
@debates = Debate.tagged_with(params[:tag]).order(id: :desc)
set_voted_values @debates.pluck(:id)
else
@debates = Debate.all.order("created_at DESC")
set_voted_values @debates.map(&:id)
@debates = Debate.all.order(id: :desc)
set_voted_values @debates.pluck(:id)
end
end

View File

@@ -8,6 +8,8 @@ class Comment < ActiveRecord::Base
belongs_to :commentable, polymorphic: true
belongs_to :user
scope :recent, -> { order(id: :desc) }
def self.build(commentable, user, body)
new commentable: commentable,
user_id: user.id,

View File

@@ -22,8 +22,8 @@
</div>
<div class="comment-children">
<%= render comment.children %>
<%= render comment.children.reorder('id DESC, lft') %>
</div>
</div>
</div>
</div>

View File

@@ -25,4 +25,4 @@
</div>
</div>
</div>
</div>

View File

@@ -43,10 +43,10 @@
<%= render 'comments/form', {parent: @debate, toggeable: false} %>
</div>
<% end %>
<%= render @debate.root_comments %>
<%= render @debate.root_comments.recent %>
</div>
<% if current_user && @debate.editable_by?(current_user) %>
<%= link_to t("debates.show.edit_debate_link"), edit_debate_path(@debate), :class => 'button radius right' %>
<% end %>
</div>
</section>
</section>