will_paginate的AJAX分页

will_paginate接受一个renderer 参数,默认是WillPaginate::LinkRenderer,更好的做法是subclass一个AjaxLinkRenderer,这样不需要修改它的源代码,在做plugin升级的时候会很方便。

Views

showgrades。rhtml

<div id ="gradedatas">
  <div id="gradelistdata">
    <% @grades = Grade.paginate_for_showgrade(params[:page]||1) %>
    <%=render :partial => "grade_list", :locals => {:grades => @grades}%>
  </div>
  <div class="huofa-ly-more">
    <%= will_paginate @grades, {   
      :renderer => 'AjaxLinkRenderer',
      :update => 'gradedatas', (要更新的div,要把will_paginate包括进去)
      :url => '/grades/ajax_paginate',
      :create => 'create();',
      :complete => 'complete();'}%>
  </div>
</div>
事发当时

你可能感兴趣的:(Ajax)