From 8c6eb8ac17de84ebd34bb26652889b4c93b7e75a Mon Sep 17 00:00:00 2001 From: jomo Date: Fri, 7 Jul 2017 02:05:04 +0200 Subject: more fixes for order of threadreplies --- app/controllers/forums_controller.rb | 2 +- app/controllers/threadreplies_controller.rb | 2 +- app/views/forums/show.html.erb | 2 +- app/views/forumthreads/index.html.erb | 2 +- app/views/threadreplies/edit.html.erb | 2 +- 5 files changed, 5 insertions(+), 5 deletions(-) diff --git a/app/controllers/forums_controller.rb b/app/controllers/forums_controller.rb index 761a86b..206f01f 100644 --- a/app/controllers/forums_controller.rb +++ b/app/controllers/forums_controller.rb @@ -11,7 +11,7 @@ class ForumsController < ApplicationController @threads = @forum.forumthreads.select {|f| f.can_read?(current_user) }.to_a @threads.sort_by! do |t| # sticky goes first, then sort by last activity (new replies) - [t.sticky ? 0 : 1, -(t.replies.last.try(:created_at) || t.created_at).to_i] + [t.sticky ? 0 : 1, -(t.replies.order(:id).last.try(:created_at) || t.created_at).to_i] end @threads = Kaminari.paginate_array(@threads).page(params[:page]) end diff --git a/app/controllers/threadreplies_controller.rb b/app/controllers/threadreplies_controller.rb index 946155d..a801fbc 100644 --- a/app/controllers/threadreplies_controller.rb +++ b/app/controllers/threadreplies_controller.rb @@ -37,7 +37,7 @@ class ThreadrepliesController < ApplicationController if @reply.update_attributes(reply_params) @reply.send_new_reply_mail(old_content) flash[:notice] = "Reply updated!" - position = @reply.thread.replies.index(@reply) + position = @reply.thread.replies.order(:id).index(@reply) page = position / Kaminari.config.default_per_page + 1 redirect_to forumthread_path(@reply.thread, page: page) + "#reply-#{@reply.id}" else diff --git a/app/views/forums/show.html.erb b/app/views/forums/show.html.erb index b232292..cfe3918 100644 --- a/app/views/forums/show.html.erb +++ b/app/views/forums/show.html.erb @@ -38,7 +38,7 @@
"> <%= render partial: "labels/label", locals: {label: thread.label} %><%= link_to truncate(thread.title, length: 60, omission: " …"), forumthread_path(thread), title: thread.title %>
- <% if rpl = thread.replies.last %> + <% if rpl = thread.replies.order(:id).last %> <%= rpl.author.name %> <% position = thread.replies.count - 1 diff --git a/app/views/forumthreads/index.html.erb b/app/views/forumthreads/index.html.erb index 02e425b..0c44352 100644 --- a/app/views/forumthreads/index.html.erb +++ b/app/views/forumthreads/index.html.erb @@ -60,7 +60,7 @@
"> <%= render partial: "labels/label", locals: {label: thread.label} %><%= link_to truncate(thread.title, length: 60, omission: " …"), forumthread_path(thread), title: thread.title %>
- <% if rpl = thread.replies.last %> + <% if rpl = thread.replies.order(:id).last %> <%= rpl.author.name %> <% position = thread.replies.count - 1 diff --git a/app/views/threadreplies/edit.html.erb b/app/views/threadreplies/edit.html.erb index c009cb0..8296d9c 100644 --- a/app/views/threadreplies/edit.html.erb +++ b/app/views/threadreplies/edit.html.erb @@ -1,7 +1,7 @@ <% title "Edit Thread Reply: #{@reply.thread.title}" %> <% - position = @reply.thread.replies.index(@reply) + position = @reply.thread.replies.order(:id).index(@reply) page = position / Kaminari.config.default_per_page + 1 %> -- cgit v1.2.3