public
Description: Tracks is a GTD(TM) web application, built with Ruby on Rails
Homepage: http://www.rousette.org.uk/projects/
Clone URL: git://github.com/bsag/tracks.git
Click here to lend your support to: tracks and make a donation at www.pledgie.com !
Changed UsersController#index to use will_paginate plugin instead of 
classic_pagination
Made corresponding change in view.
Added User.per_page method to provide number of users per page to User.paginate 
button.  I can remove and just pass the param to the method in the controller if 
that is more desirable.
Added 2 controller tests for pagination.  No view tests have been added.
MHarris (author)
Mon Jul 14 10:10:55 -0700 2008
commit  ed76cf55d29cb07e405dbea0539cef5a52ff6055
tree    9e38dc065c6eb7b688475f774dfe7c543cdc95e7
parent  2f1b15fed34c1a5cec4c4e81bbf139d71f79106c
...
16
17
18
19
 
20
21
22
...
16
17
18
 
19
20
21
22
0
@@ -16,7 +16,7 @@ class UsersController < ApplicationController
0
     respond_to do |format|
0
       format.html do
0
         @page_title = "TRACKS::Manage Users"
0
-        @user_pages, @users = paginate :users, :order => 'login ASC', :per_page => 10
0
+        @users = User.paginate :page => params[:page], :order => 'login ASC'
0
         @total_users = User.count
0
         # When we call users/signup from the admin page
0
         # we store the URL so that we get returned here when signup is successful
...
103
104
105
 
 
 
 
106
107
108
...
103
104
105
106
107
108
109
110
111
112
0
@@ -103,6 +103,10 @@ class User < ActiveRecord::Base
0
   before_create :crypt_password, :generate_token
0
   before_update :crypt_password
0
   before_save :normalize_open_id_url
0
+
0
+  #for will_paginate plugin
0
+  cattr_accessor :per_page
0
+  @@per_page = 1
0
   
0
   def validate
0
     unless Tracks::Config.auth_schemes.include?(auth_type)
...
29
30
31
32
33
 
34
35
36
37
...
29
30
31
 
 
32
33
34
35
36
0
@@ -29,8 +29,7 @@
0
   <% end %> 
0
   </table>
0
   <p>
0
-    <%= link_to "&laquo; Previous page", { :page => @user_pages.current.previous } if @user_pages.current.previous %> &nbsp;
0
-    <%= link_to "Next page &raquo;", { :page => @user_pages.current.next } if @user_pages.current.next %>
0
+    <%= will_paginate @users %>
0
   </p>
0
  
0
   <p><%= link_to 'Signup new user', signup_path %></p>
0
\ No newline at end of file
...
34
35
36
 
 
 
 
 
 
 
 
 
 
 
 
 
 
37
38
39
...
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
0
@@ -34,6 +34,20 @@ class UsersControllerTest < Test::Rails::TestCase
0
     assert_equal 3, assigns['total_users']
0
     assert_equal "/users", session['return-to']
0
   end
0
+
0
+  def test_index_pagination_page_1
0
+    User.per_page = 1
0
+    login_as :admin_user
0
+    get :index
0
+    assert_equal assigns['users'],[User.find_by_login('admin')]
0
+  end
0
+
0
+  def test_index_pagination_page_2
0
+    User.per_page = 1
0
+    login_as :admin_user
0
+    get :index, :page => 2
0
+    assert_equal assigns['users'],[User.find_by_login('jane')]
0
+  end
0
   
0
   def test_destroy_user
0
     login_as :admin_user

Comments