From e21843eca82b4751ece3e50fa977a1cb7d6c3b01 Mon Sep 17 00:00:00 2001 From: Dave Vasilevsky Date: Thu, 8 Sep 2016 00:13:50 -0400 Subject: [PATCH] Update recent wiki pages; paginate --- app/controllers/recent_wiki_pages_controller.rb | 12 +++++++----- app/views/my/blocks/_recent_wiki_pages.html.erb | 4 +++- app/views/recent_wiki_pages/date_index.html.erb | 4 ++++ 3 files changed, 14 insertions(+), 6 deletions(-) diff --git a/app/controllers/recent_wiki_pages_controller.rb b/app/controllers/recent_wiki_pages_controller.rb index 29976a9..3dbe083 100644 --- a/app/controllers/recent_wiki_pages_controller.rb +++ b/app/controllers/recent_wiki_pages_controller.rb @@ -1,11 +1,13 @@ class RecentWikiPagesController < ApplicationController + def self.pages_with_updated_on + WikiPage.with_updated_on + .joins(:content) + .order("#{WikiContent.table_name}.updated_on DESC") + end + def date_index - @pages = WikiPage.find :all, - :select => "#{WikiPage.table_name}.*, #{WikiContent.table_name}.updated_on", - :joins => "LEFT JOIN #{WikiContent.table_name} ON #{WikiContent.table_name}.page_id = #{WikiPage.table_name}.id", - :order => "#{WikiContent.table_name}.updated_on DESC" + @paginator, @pages = paginate self.class.pages_with_updated_on @pages_by_date = @pages.group_by {|p| p.updated_on.to_date} - @pages_by_parent_id = @pages.group_by(&:parent_id) @pages.first.wiki end diff --git a/app/views/my/blocks/_recent_wiki_pages.html.erb b/app/views/my/blocks/_recent_wiki_pages.html.erb index 33f6cb3..3538767 100644 --- a/app/views/my/blocks/_recent_wiki_pages.html.erb +++ b/app/views/my/blocks/_recent_wiki_pages.html.erb @@ -1,6 +1,8 @@ <% #see WikiController::load_pages_for_index -pages = WikiPage.with_updated_on.find :all, :order => "updated_on DESC", :limit => 10,:include => {:wiki => :project} +pages = RecentWikiPagesController.pages_with_updated_on + .limit(10) + .includes(:wiki => :project) %>

Top 10 Most Recent Wiki Pages

diff --git a/app/views/recent_wiki_pages/date_index.html.erb b/app/views/recent_wiki_pages/date_index.html.erb index 48dd3eb..46607e5 100644 --- a/app/views/recent_wiki_pages/date_index.html.erb +++ b/app/views/recent_wiki_pages/date_index.html.erb @@ -13,3 +13,7 @@ <% end %> <% end %> + + + <%= pagination_links_full @paginator, :per_page_links => true %> +