Rails3 will_paginateajaxページング



Rails3 Will_paginate Ajax Paging



方法1:

1.ビューレイヤー(lists / show.html.erb)



‘comments' %>

jsファイルに追加:

def show @comments=ZyComment.order('created_at desc').paginate :per_page=>5, :page=>params[:page]||1 respond_to do |format| format.html Format.js #ajax paging end end

2.コントローラーレイヤー(表示)



$('#comments').html(''comments') %>') $('.pagination a').attr('data-remote', 'true')

3.jsテンプレート(ファイルshow.js.erb)

注:showファイルに他のjsエフェクトがある場合は、それらをshow.js.erbファイルにリロードしてください。

' Previous' , #This is generally used on our Chinese website when the time needs to be corrected, the default is <' Next Page', #This is generally used on our Chinese website to correct the time, the default is Next>> :inner_window => 4, # inner_window? Grasp the few links that show the current page, the default is 4 :outer_window => 1 , # outer_window Grab the first few links in the first/last page. The default is 1. :page_links => false, # If it is false, only the previous and next pages are displayed (default is true) :separator => '|', # This parameter is used to set the separator between page numbers, with spaces or (|) or other :param_name => :page, #This parameter is the name of the parameter that we use to pass the time of the page number connection. :class=>'pagination', #This is the class name used to give the paginated element home heml, which can be styled by this class name. :container=>true #default value is true, whether to add the outer div }%>

4.will_paginateパラメータ設定



class RemoteLinkRenderer target } @template.link_to( text.to_s.html_safe, target, :remote => true ) end end

方法2:

|_+_|

Will_paginateいくつかのAPI:

Total_pagesはページの総数を取ります

Current_page現在のページ

Total_entriesは合計レコードを取得します