order comments by the most recent first
This commit is contained in:
@@ -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
|
||||
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -22,8 +22,8 @@
|
||||
</div>
|
||||
|
||||
<div class="comment-children">
|
||||
<%= render comment.children %>
|
||||
<%= render comment.children.reorder('id DESC, lft') %>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -25,4 +25,4 @@
|
||||
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -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>
|
||||
|
||||
Reference in New Issue
Block a user