超级简单等ajax 分页
.../application.html.erb #如果不想每个页面都加载单独放到需要的页面。<%= javascript_include_tag 'jquery','pagination' %>
www.jequery.com
../controller/news_controller.rb
......
def index
@news = News.paginate(:per_page=>10,:page => params[:page])
end
......
.../public/javascripts/pagination.js
$(function() {$(".pagination a").live("click", function() { $.get(this.href, null, null, "script"); return false;});});
.../news/index.html.erb
<div id="news"><%= render :partial => 'news' %></div>
.../news/_news.html.erb
<table width="100%"><tr> <th>标题</th> <th>描述</th> <th>是否公开</th> <th>公开时间</th></tr><% @news.each do |news|%> <tr> <td><%= news.title %></td> <td><%= news.description %></td> <td><%= news.is_public ? "是" : "否" %></td> <td><%= news.public_date.strftime("%Y.%m.%d") %></td> </tr><% end %></table><%= will_paginate @news %>
.../news/index.js.erb
$("#news").html("<%= escape_javascript(render("news")) %>");
页:
[1]