rails will_paginate ajax

http://www.tricksonrails.com/2010/04/rails3-and-will_paginate-doing-easy-remote-links-rails3-tricks-02/


As you know, Rails3 use only UJS (unobtrusive javascript), so for every remote link, Rails3 just add the data-remote attribute to links :

<a href="ajax_page.html" data-remote="true">A remote link ! </a>

If you want to do ajaxed pagination, there is no easy way with will_paginate to do remote link (or I didn’t find any one), but with Rails3 UJS, there is a little tricks do to this easily !

Here is the haml and jquery code :

= will_paginate (@users )
:javascript
$ ( '.pagination a' ). attr ( 'data-remote', 'true' );

This snippet of code just add the attribute data-remote to pagination links. And that’s it ! Our pagination will now be ajaxed :)



------------------------------------------------------------

$$('.pagination a').each(function(e){
var link=e.getAttribute('href');
e.setAttribute(
'onclick',
'new Ajax.Request(\'' + link + '\', {asynchronous:true, evalScripts:true})');
e.writeAttribute('href',null);
}



评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值