Created
January 22, 2011 17:38
-
-
Save CootCraig/791291 to your computer and use it in GitHub Desktop.
storing page on session for will_paginate
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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