Do you want will_paginate with AJAX functionality ?
Follow:
- Remove will_paginate plugin if you have it (/vendor/plugins/) /or backup it.
- in command line:
gem sources -a http://gems.github.com
- in command line:
gem install mislav-will_paginate
Rails::Initializer.run do |config|Next step, create new helper: remote_link_renderer.rb .. and copy&paste inside:
...
end
require 'will_paginate'
Now, to ajaxize put:
class RemoteLinkRenderer < WillPaginate::LinkRenderer
def prepare(collection, options, template)
@remote = options.delete(:remote) || {}
super
end
protected
def page_link(page, text, attributes = {})
@template.link_to_remote(text, {:url => url_for(page), :method => :get}.merge(@remote))
#replace :method => :post if you need POST action
end
end
<%= will_paginate :collection, :renderer => "RemoteLinkRenderer",:remote => {:with => "something_you_want", :update => "dom_id_element"} %>
And you are happy-ajax-paginator !
Sample:
<%= will_paginate @events, :renderer => "RemoteLinkRenderer",:remote => {, :update => "events_container", :loading => visual_effect(:appear, "loader"),:complete =>visual_effect(:fade,"loader" ) } %>will call /events?page=x with AJAX request..
in my EventController:
respond_to do |format|
format.html { }
format.js { render :partial => "events" }
format.xml { render :xml => @events.to_xml }
end
Thats all !!
More info about will_paginate plugin here
Original post here