RubyonRails

Pagination in Rails

Pagination :

Inside method

if params[:Pincode]
session[:location] = params[:Pincode]
end
location = session[:location]
# @locations_pages, @locations = paginate :companies, :per_page =>2, :conditions=>[“location like ?”, “%#{location}%”]

@locations_pages, @zipdetail = paginate :zipdatas, :per_page =>5,:conditions  =>[“Pincode like?”,”%#{location}%”]

View :

<% for c in @zipdetail %>
<table border=’1′>
<tr><td> <%= c.Pincode %> </td>
<td> <%= c.OfficeName %> </td>
<td> <%= c.Status %> </td>
<td> <%= c.Suboffice %> </td>
<td> <%= c.HeadOffice %> </td>
<td> <%= c.OfficeName %> </td>
<td> <%= c.Location %> </td>
<td> <%= c.Telephone %> </td>
<td> <%= c.SPCC %> </td>
<td> <%= c.Postal %> </td>
<td> <%= c.Division %> </td>
<td> <%= c.Region %> </td>
<td> **************** </td>

</tr>
</table>
<% end %>

<%= link_to ‘[previous]’, { :page => @locations_pages.current

.previous } \
if @locations_pages.current.previous %>
<%= pagination_links(@locations_pages) %>
<%= link_to ‘[next]’, { :page => @locations_pages.current.next } \
if @locations_pages.current.next %>

<%= link_to ‘Back to Search’, :action => ‘show’ %>
<%= link_to ‘Home Page’, {:action => ‘index’, :controller => ‘home’}, {:accesskey => 3} %>