]> git.openstreetmap.org Git - rails.git/commitdiff
Add pagination to diary entry lists.
authorTom Hughes <tom@compton.nu>
Fri, 18 Jan 2008 18:20:15 +0000 (18:20 +0000)
committerTom Hughes <tom@compton.nu>
Fri, 18 Jan 2008 18:20:15 +0000 (18:20 +0000)
app/controllers/diary_entry_controller.rb
app/views/diary_entry/list.rhtml

index 28eb903a347719b453e94c9bb5aedcbeaa5a6a18..13d3121a5eef32de418f4beada6a907df5570428 100644 (file)
@@ -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
 
index e05e90531dbc630522c9b4a1a1b89a8ae819f0b7..31c370c6d2e78027181b80a0370b8eea1236fd3c 100644 (file)
 
 <%= 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 %>
+
+<br />
+
 <%= link_to(image_tag("RSS.gif", :size => "16x16", :border => 0), :action => 'rss') %>
 <%= auto_discovery_link_tag(:atom, :action => 'rss') %>