JasonChi 发表于 2013-1-23 01:44:33

rails 分页插件will_paginate ajax 实现

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         end      else      @template.content_tag :span, text, :class => classnames.join(' ')       end    endend
嗯,很好用。在config\initializers下面做成一个.rb。页面上的Ajax分页就可以用了。页面上的处理是下面的代码:
<%= will_paginate @producttradeinfos,            {:class=>'pagination',            :prev_label => '上一页',            :next_label => '下一页',            :renderer => 'AjaxLinkRenderer',            :update => 'results',             :params => {你的参数(如: :q => params[:q])}}%>
页: [1]
查看完整版本: rails 分页插件will_paginate ajax 实现