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 => '>')%>
本文介绍了一种使用Rails框架中的will_paginate插件实现远程分页的方法。通过在application_helper.rb文件中定义will_paginate_remote辅助方法,可以为分页链接添加AJAX更新功能。这种方法避免了页面的完全刷新,提升了用户体验。
183

被折叠的 条评论
为什么被折叠?



