Posts

Showing posts with the label will_paginate

Making Will Paginate Ajax + Rails 3

1. Create a helper file : app / helpers / remote_link_pagination_helper.rb module RemoteLinkPaginationHelper   class LinkRenderer < WillPaginate::ActionView::LinkRenderer     def link(text, target, attributes = {})       attributes['data-remote'] = true       super     end   end end 2. In the View File where pagination links come, add this line. (@people is the array to paginate) will_paginate @people, :renderer => 'RemoteLinkPaginationHelper::LinkRenderer' Now the links must work with Ajax

Will Paginate - Array Pagination

Image
Wanna paginate an Array using will paginate.. Here is how i did.. Add this as method, Array.class_eval do def paginate(page=1, per_page=15) pagination_array = WillPaginate::Collection.new(page, per_page, self.size) start_index = pagination_array.offset end_index = start_index + (per_page - 1) array_to_concat = self[start_index..end_index] array_to_concat.nil? ? [] : pagination_array.concat(array_to_concat) end end And with the array @results do @results.paginate reference: http://www.devchix.com/2007/07/23/will_paginate-array/ Regards, Srikanth Learn to Program with Ruby | Ruby Pocket Reference

Will Paginate Ajax pagination

I have gone through many articles on how to use Ajax pagination with will_paginate. Here is how i did & it worked for me, Step 1 : Create a helper called remote_link_renderer.rb and use the following code, 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), attributes) end end Step 2: Make the view file table in a partial(_units.html.erb), <div id="units"> <%= render :partial => "units" %> </div> Step 3 : And in the partial _units.html.erb add will paginate code, <%= will_paginate @units, :renderer => 'RemoteLinkRenderer' , :remote => { :update => 'units'} %> Step 4 : In the controller use: respond_to do |format| format.js { render :partial =...