Joshua Rechanek
2005-Mar-29 20:29 UTC
Can''t get pagination to work with Pagination Helper
Advance apologies from the Rails rookie. Although I can get my view to display pagination controls and the correct page number is passed as a URL parameter to the controller, the records shown do not change when I move from page to page. My code is as follows: [controllers/unit_controller.rb] class UnitController < ApplicationController model :Unit def list @unit_pages, @current_units = paginate(:units, :order_by => ''internal_code'') end end [views/unit/list.rhtml] <%= pagination_links(@unit_pages) %> <table> <tr> <th>ID</th> <th>internal_code</th> <th>client_code</th> <th>description</th> <th>manufacturer</th> </tr> <% @current_units.each do |@current_unit| %> <tr> <td><%= @current_unit.id %></td> <td><%= @current_unit.internal_code %></td> <td><%= @current_unit.client_code%></td> <td><%= @current_unit.description%></td> <td><%= @current_unit.manufacturer_name%></td> </tr> <% end %> </table> [end code] I''m running the database on Microsoft SQL Server 2000, and my Rails is 0.11.1. Can you spot anything wrong with this code or should I direct my attention to the database? Josh
On Tue, 29 Mar 2005 16:29:36 -0400, Joshua Rechanek <josh-zulXKkpI+OpZroRs9YW3xA@public.gmane.org> wrote:> I''m running the database on Microsoft SQL Server 2000, and my Rails is > 0.11.1. Can you spot anything wrong with this code or should I direct my > attention to the database?The code looks fine though i''m not sure about the database. IIRC there was one db that didn''t work at all with pagination because it didn''t properly support the limit...offset thing that was used... I thought it was DB2 but it might have been MS SQL Server... does anybody remember? For the record, here''s working pagination code from my rails project: in the controller: class PhotosController < ApplicationController model :photo [... snip ...] def list @photo_pages, @photos paginate :photos, :order_by => ''created_on DESC'', :per_page => 16 # 4x4 grid end [... snip ...] end in the view: <p id="prev_next"><%= get_link_page(@photo_pages.current.next, ''«'') %> — <%= get_link_page(@photo_pages.current.previous, ''»'') %></p> and in the helper: def get_link_page(page, text) if page link_to text, :page => page else text end end (just a convenience method because I still want the link text to appear as plain text if there''s nothing to link to). And yes, the observant will note that I link to the "next" page with the back arrow and to the "previous" page with the forward arrow, that''s because my content is sorted by date descending, newest stuff is always on page one, so I wanted it to appear like going "back" even though you''re going to the next page. -- Urban Artography http://artography.ath.cx