2

最近、Rails(2.3.4)アプリでwill_paginateを使用してページネーションを変更し、ページごとのページネーションとレコードにAjaxを使用するようにしました。ページ付けは、ここで説明されている方法を使用して行われました:http: //github.com/mislav/will_paginate/wiki/Ajax-pagination

私は自分の見解でこのコードを使用しています:

Records per page: <%= select_tag :per_page, options_for_select([4,8,24,100,500], @per_page.to_i), :onchange => remote_function(:url => users_path, :method => :get, :with => "'per_page=' + this.getValue()") %>

検索結果を表示していない場合、これは正常に機能します。しかし、検索を行ってページあたりのレコード数を変更しようとすると、検索結果が失われ、すべてのレコードが返されます。これは、remote_functionで呼び出しているURLが原因であると確信していますが、修正方法がわかりません。

これは私のコントローラーのコードです:

def index
@search = User.search(params[:search])
@search.order||="ascend_by_last_name"
if @search.count > 0
  @users = @search.paginate(:page => params[:page], :per_page => users_per_page )
  respond_to do |format|
    format.html # index.html.erb
    format.xml { render :xml => @users }
    format.csv { send_data @users.to_csv }
    format.js {
          render :update do |page|
            # 'page.replace' will replace full "results" block...works for this example
            # 'page.replace_html' will replace "results" inner html...useful elsewhere
            page.replace 'results', :partial => 'userview'
          end
      }      
    end
else
  flash[:notice] = "Sorry, your search didn't return any results."
  redirect_to users_path
end

終わり

どんな助けでもいただければ幸いです!ありがとう。

4

1 に答える 1

0

per_pageパラメータを現在のクエリ文字列の最後に追加できます。

:with => "'#{request.query_string}&per_page=' + this.getValue()"

これは、問題を引き起こす可能性のある現在のクエリ文字列があることを前提としています。

于 2011-05-12T19:42:26.967 に答える