Rails Note #6: Pagination
-
will_paginate docs
Main http://github.com/mislav/will_paginate/wikis
Reference http://mislav.uniqpath.com/static/will_paginate/doc/
Clone URL: git://github.com/mislav/will_paginate.git -
Installation as a gem
http://github.com/mislav/will_paginate/wikis/installation
gem sources -a http://gems.github.com
Once installed, do script/server
- Controller
class PoiAppController < ApplicationController def poi_by_category mylimit = 100 sql = "SELECT pa.* FROM poi_apps pa WHERE pa.id IN " + "(" + "SELECT pc.poi_app_id " + "FROM poi_categories pc " + "WHERE pc.categ_node_id LIKE '" + params[:node_id] + "%%'" + "LIMIT " + mylimit.to_s + ")" #@poi_apps = PoiApp.find_by_sql(sql) @poi_apps = PoiApp.paginate_by_sql [sql], :page => params[:page], :per_page => 10 end end |
- View
<h2>POIs</h2>
<div clas="page_info">
<%= page_entries_info @poi_apps %>
</div>
<table>
<tr>
<td>POI_APP_ID</td>
<td>CN_NAME</td>
<td>EN_NAME</td>
</tr>
<% for poi in @poi_apps %>
<tr>
<td><%= poi.id %></td>
<td><%= poi.cn_name %></td>
<td><%= poi.en_name %></td>
</tr>
<% end %>
</table>
<%= will_paginate @poi_apps %>
|
- Checkout the styles http://mislav.uniqpath.com/static/will_paginate/