Installation of mislav's will_paginate.
In previous rails versions the PaginationHelper was in bilt but in later versions (Rails 2.0) it is deleted. There are two ways to install the will paginate.- use the gem(recommended)
- install as Rails plugin using git
I have put that in the vender/gems folder.
Here is the process :
Gem Installation.
- Download the gem from the Git Hub :
- Put this in vender/gems folder.
- Put the following code in environment.rb file :
- Now in your controller write the code for pagination :
- The pagination partial will look like this : -
- The index.rhtml file will be :
git clone git://github.com/mislav/will_paginate.git
config.gem "mislav-will_paginate", :version => "2.3.6", :lib => "will_paginate"
def index
@posts = Post.paginate(:all, :page => params[:page], :per_page => 6)
respond_to do |format|
format.html { }
format.js {
render :update do |page|
page.replace_html 'all-posts', :partial => @posts
page.replace_html 'pagination', :partial => 'pagination',
:locals => {:collection => @posts}
end
}
format.xml { render :xml => @posts }
end
end
There will be two partials one for showing the posts and other for the pagination helper.
<%= will_paginate collection, :remote => "true", :params => { :paginated => true } %>
index.html.erb :-
<%= render :partial => @posts %>
<%= will_paginate @posts, :remote => "true" %>