我最近在 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
结尾
任何帮助,将不胜感激!谢谢。