Skip to content

Instantly share code, notes, and snippets.

@CootCraig
Created January 22, 2011 17:38
Show Gist options
  • Save CootCraig/791291 to your computer and use it in GitHub Desktop.
Save CootCraig/791291 to your computer and use it in GitHub Desktop.
storing page on session for will_paginate
class ApplicationController < ActionController::Base
...
before_filter :page_params, :only => :index
def page_key
(self.class.to_s + "_page").to_sym
end
# Use a before_filter on index action to remember the current page
# for will_paginate. This applies to all controllers.
def page_params
if params[:page] then
session[page_key] = params[:page]
elsif session[page_key]
params[:page] = session[page_key]
end
end
class FriendController < ApplicationController
def index
@page_title = "Friend List"
@friends = TwitterUser.paginate(:page => params[:page], :order => 'screen_name')
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment