Show All Results With The will_paginate Gem

A partial solution to getting will_paginate to show all the results on the one page.

I chose to stick the link that will cause all the results to be displayed inside the pagination menu using jQuery.
This should go in your view

// Create the link
var show_all_link = ' @matches.size, :page => 1), :class => "show-all" %>';
$('a.next_page, span.next_page').after(show_all_link); // Place the link after the next page link

And this in your controller

per_page = params[:show] || 50 # How many items to display
@paginated_matches = @matches.paginate(:page => params[:page], :per_page => per_page)

I say it’s only a partial solution because will_paginate will not display the pagination menu when displaying all results like this. If I come up with a workaround or a better solution I’ll post it here, but if any of you guys have any success stick it in the comments and I’ll edit the post appropriately.

James.

Advertisements
This entry was posted in jQuery, Ruby on Rails, Uncategorized and tagged , . Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s