Fixes forum topic ordering by latest post

This commit is contained in:
Luke Barratt 2014-08-10 20:41:05 +01:00
parent 5900a6602f
commit d40e0e4c46

View file

@ -11,9 +11,10 @@ class ForumsController < ApplicationController
raise AccessError unless @forum.can_show? cuser
@topics = Topic.where(forum_id: @forum.id)
.includes(:posts, :user, :users_who_read, :lock)
.joins(posts: :user)
.includes(:lock, :readings)
.group('topics.id')
.order('state DESC, posts.id DESC')
.order('state DESC, (SELECT created_at FROM posts p2 WHERE p2.topic_id = topics.id ORDER BY created_at DESC LIMIT 1) DESC')
.paginate(page: params[:page], per_page: 30)
@forum.read_by! cuser if cuser