From: Tom Hughes Date: Fri, 18 Jan 2008 18:20:15 +0000 (+0000) Subject: Add pagination to diary entry lists. X-Git-Tag: live~8513 X-Git-Url: https://git.openstreetmap.org./rails.git/commitdiff_plain/691aab02fcd76cde87e0f55ddf61b3a288ab5a36 Add pagination to diary entry lists. --- diff --git a/app/controllers/diary_entry_controller.rb b/app/controllers/diary_entry_controller.rb index 28eb903a3..13d3121a5 100644 --- a/app/controllers/diary_entry_controller.rb +++ b/app/controllers/diary_entry_controller.rb @@ -30,10 +30,15 @@ class DiaryEntryController < ApplicationController if params[:display_name] @this_user = User.find_by_display_name(params[:display_name]) @title = @this_user.display_name + "'s diary" - @entries = DiaryEntry.find(:all, :conditions => ['user_id = ?', @this_user.id], :order => 'created_at DESC') + @entry_pages, @entries = paginate(:diary_entries, + :conditions => ['user_id = ?', @this_user.id], + :order => 'created_at DESC', + :per_page => 20) else @title = "Users' diaries" - @entries = DiaryEntry.find(:all, :order => 'created_at DESC', :limit => 20) + @entry_pages, @entries = paginate(:diary_entries, + :order => 'created_at DESC', + :per_page => 20) end end diff --git a/app/views/diary_entry/list.rhtml b/app/views/diary_entry/list.rhtml index e05e90531..31c370c6d 100644 --- a/app/views/diary_entry/list.rhtml +++ b/app/views/diary_entry/list.rhtml @@ -13,5 +13,11 @@ <%= render :partial => 'diary_entry', :collection => @entries %> +<%= link_to "Older Entries", { :page => @entry_pages.current.previous } if @entry_pages.current.previous %> +| +<%= link_to "Newer Entries", { :page => @entry_pages.current.next } if @entry_pages.current.next %> + +
+ <%= link_to(image_tag("RSS.gif", :size => "16x16", :border => 0), :action => 'rss') %> <%= auto_discovery_link_tag(:atom, :action => 'rss') %>