diff --git a/app/controllers/wikis_controller.rb b/app/controllers/wikis_controller.rb index 55ccfe7211615583d974dce4fad206a5e8627742..c605a36929315dc380ea4defa5a8183ed7bbc819 100644 --- a/app/controllers/wikis_controller.rb +++ b/app/controllers/wikis_controller.rb @@ -7,7 +7,7 @@ class WikisController < ApplicationController layout "project" def pages - @wikis = @project.wikis.group(:slug).order("created_at") + @wikis = @project.wikis.last_revisions.order("created_at") end def show diff --git a/app/models/wiki.rb b/app/models/wiki.rb index ebb1ff49c7a07e8f68d625beaf7c76433520c7c2..7b690f0abd1bfc67fa954f42786db88d336bf765 100644 --- a/app/models/wiki.rb +++ b/app/models/wiki.rb @@ -28,6 +28,21 @@ class Wiki < ActiveRecord::Base end new_wiki end + + # Scope with last revisions of pages (i.e. newest page per project_id + # and slug). + # + # This is instead of Wiki.group(:slug).order(:created_at) which in this + # case generates query violating SQL standard (thus doesn't work on PgSQL). + # + # return: + # ActiveRecord::Relation + # + def last_revisions + t1 = arel_table.alias(table_name + '1') + where(created_at: from(t1).select(t1[:created_at].maximum) + .where(project_id: t1[:project_id], slug: t1[:slug])) + end end end # == Schema Information