rails ajax 分页 带参数

1. 在application_helper.r中定义will_paginate_remote helper:

def will_paginate_remote(paginator, options={})
  update = options.delete(:update)
  url = options.delete(:url)
  params = options.delete(:params)
  str = will_paginate(paginator, options)
  if str != nil
    str.gsub(/href="(.*?)"/) do
      "href=\"#\" onclick=\"new Ajax.Updater('" + update + "', '" + (url ? url +$1.sub(/[^\?]*/, '')+ params.to_s : $1) +
      "', {asynchronous:true, evalScripts:true, method:'get'}); return false;\""
    end
  end
end

 2. 在view中调用will_paginate_remote:

<%= will_paginate_remote(@knowledges,:class=>'meneame',:update=>'aa01', :url=>"/diarys/pages",:params=>'&lb=knowledges',:prev_label   => '<',
  :next_label   => '>')%>

 

你可能感兴趣的:(Ajax,Rails)