使用插件
1/ will_paginate
http://groups.google.com/group/will_paginate
这个资料很多,不多说
2/ squirrel
下载:http://github.com/thoughtbot/squirrel/tree/master
主要实现 动态条件的查询,扩展ActiveScaffold find方法。支持跨Model查询,具体见
说明:http://thoughtbot.com/projects/squirrel
贴段主要实现代码
#controller:
def index
#######################################################
#下面代码可以按实际情况提取到Model或其他地方;方便测试我直接放在index下
#######################################################
@permissions = Permission.find(:all) do
paginate :page => params[:page]||1,:per_page=>5
any do
name == params[:permission][:name] unless params[:permission].nil?
code == params[:permission][:code] unless params[:permission].nil?
permit_date == params[:permission][:permit_date] unless params[:permission].nil?
contact.company == params[:contact][:company] unless params[:contact].nil?
end
end
#######################################################
respond_to do |format|
format.html # index.rhtml
format.xml { render :xml => @permissions.to_xml }
end
end
#index--view
<% field_set_tag do %>
<% form_for :permission, :url=>permissions_url,:method=>:get,:html=>{:method=>:get} do |f| %>
公司名称 :<%= text_field_with_auto_complete :contact, :company,{},{:method=>:get}%> <br>
证书类型 :<%= text_field_with_auto_complete :permission, :name,{},{:method=>:get}%> <br>
证书编号 :<%= text_field_with_auto_complete :permission, :code,{},{:method=>:get}%> <br>
授与日期 :<%= text_field_with_auto_complete :permission, :permit_date,{},{:method=>:get}%> <br>
<%= submit_tag '查询' %>
<% end %>
<% end %>
...
<div class="digg_pagination">
<div clas="page_info">
<%= page_entries_info @permissions %>
</div>
<%= will_paginate @permissions, :container => false %>
</div>