六狼论坛

 找回密码
 立即注册

QQ登录

只需一步,快速开始

新浪微博账号登陆

只需一步,快速开始

搜索
查看: 37|回复: 0

超级简单等ajax 分页

[复制链接]

升级  74%

43

主题

43

主题

43

主题

秀才

Rank: 2

积分
161
 楼主| 发表于 2013-1-23 01:46:19 | 显示全部楼层 |阅读模式
.../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")) %>");
您需要登录后才可以回帖 登录 | 立即注册 新浪微博账号登陆

本版积分规则

快速回复 返回顶部 返回列表