firstruby

Master ruby with us

Archive for November, 2009

AJAX pagination in Ruby on Rails

Posted by firstruby on November 29, 2009

For users list, I wanted to have AJAX pagination.

For Ruby on Rails version 2.3.x,

1) Install will_paginate gem “config.gem “will_paginate”” or include will_paginate plugin in vendor/plugins.

2) Create helper file at /app/helpers/remote_link_renderer.rb with following content,
remote_link_renderer.rb
Here I’m attaching remote_link_renderer.rb.pdf file , copy contents from remote_link_renderer.rb.pdf and create file remote_link_renderer.rb

3) In controller action, write as following,

if request.xhr?
render :update do |page|
page.replace_html "users_list", :partial => "users", : object => @users
end
end

4) On “_users_list.html.erb” view page, write as,

= will_paginate @users, :renderer => 'RemoteLinkRenderer'

Posted in Useful Links | Tagged: , , , , | Leave a Comment »