|
May
21
|
‘will_paginate‘ is one of the most widely used plugins in most of the ruby on rails projects.will_paginate is an alternative to the classic_pagination plugin, which is the pagination plugin that basically took the pre Rails 2.0 pagination implementation and packaged it in plugin form
1.How to Install will_paginate
the simple method
gem install mislav-will_paginate
There are some other method you can find it here.
2.Example
In controller
@gallery=Gallery.find(:all,:order=>”position asc”).paginate :page => page,:per_page=>10
where :per_page passes the number of gallery you want to display.You can change it according to your need 1-100
will_paginate defines it to be 30 by default
In View
you can simply use
<%= will_paginate @gallery %>
some advanced …
<% if @gallery.previous_page %>
<%= will_paginate @gallery,:page_links=>false, :next_label => “”, :prev_label => image_tag(“/images/icon/arrow.png”, :border => “0″) %>
<% end %>
<% if @gallery.next_page %>
<%= will_paginate @gallery,:page_links=>false, :next_label => image_tag(“/images/icon/arrow.png”,, :border => “0″), :prev_label => “” %>
<% end %>
If we put page_links=>false then it won’t display 1,2,3… and next_label and prev_label => “” as null it won’t display Next and Prev
Ryan Bates made an awesome screencast check it out here
June 15th, 2009 at 3:21 am
Thank you so much for this post. I use the reviewazon plugin.