Topic: pagination returning incorrect number of pages.
i have a controller where i need to return paginated records from two different Models.
the first one is Subscriptions, the other Requests. I am listing both on the same page, with ajax pagination.
the subscription pagination works fine:
[code = ruby]
@subscription_pages = Paginator.new(Subscription, Subscription.count, 10, params[:page])
@subscriptions = Subscription.find(:all, :conditions => ["subscriptions.user_id = ?", session[:rbac_user].id],
:include => [:request],
:order => "requests.last_action DESC",
:limit => @subscription_pages.items_per_page,
:offset => @subscription_pages.current.offset)
but on the requests, i couldnt use 'Request.count' as an argument for the Paginator constructor. when i did, pagination was showing 5+ pages even though i had only retrieved 3 records. So i had to retrieve my records, use '@request.length' as the constructor argument, and retrieve the records again, with pagination options, like so:
[code = ruby]
@requests = Request.find(:all, :conditions => ["user_id = ?", session[:rbac_user].id])
@request_pages = Paginator.new(Request, @requests.length, 10, params[:page])
@requests = Request.find(:all, :conditions => ["user_id = ?", session[:rbac_user].id],
:order => "last_action ASC",
:limit => @request_pages.items_per_page,
:offset => @request_pages.current.offset)
and i'm pretty sure requesting the same records twice within a single method kills kittens and blinds small children.
Last edited by smoothoperatah (2007-01-10 12:42:22)