六狼论坛

 找回密码
 立即注册

QQ登录

只需一步,快速开始

新浪微博账号登陆

只需一步,快速开始

搜索
查看: 50|回复: 0

rails 分页插件will_paginate ajax 实现

[复制链接]

升级  10.67%

18

主题

18

主题

18

主题

秀才

Rank: 2

积分
66
 楼主| 发表于 2013-1-23 01:44:33 | 显示全部楼层 |阅读模式
class AjaxLinkRenderer < WillPaginate::LinkRenderer     def page_link_or_span(page, span_class = 'current', text = nil)       text ||= page.to_s       classnames = Array[*span_class]        if page and page != current_page         if @options[:update]           @template.link_to_remote text, :update => @options[:update], :url => url_for(page)         else          @template.link_to text, url_for(page), :rel => rel_value(page), :class => classnames[1]         end      else        @template.content_tag :span, text, :class => classnames.join(' ')       end    end  end
嗯,很好用。在config\initializers下面做成一个.rb。页面上的Ajax分页就可以用了。页面上的处理是下面的代码:
<%= will_paginate @producttradeinfos,            {:class=>'pagination',              :prev_label => '上一页',              :next_label => '下一页',              :renderer => 'AjaxLinkRenderer',              :update => 'results',             :params => {你的参数(如: :q => params[:q])}}%>
您需要登录后才可以回帖 登录 | 立即注册 新浪微博账号登陆

本版积分规则

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