Will Paginate Page_Entries_Info Hide/Show

The old standby Rails pagination plugin, Will Paginate has an excellent built-in method for showing the records found in a collection:


<%= page_entries_info @modelobjects %>

What this does is returns a count of the model objects in your collection. This sometimes helpful, for example, if you want to show your users how many comments a blog post has. Or if you want to show your your user how many objects were in the total collection as they click through your pages.

Here’s an example of how I use this in one of my applications, Studentbase, a martial arts software program.

If no objects are returned, Will Paginate helpfully returns “no entries found”. But sometimes you don’t want your users to know how many objects exist in a given collection.

For example, in a new project I developed, DJ Search, a site to find professional dj’s for your event, the total number of dj’s isn’t relevant. Users only want to see how many dj’s were found in their search.

In this app, I used the “apple pagination” provided by Will Paginate, which works nicely with the minimal design of the site:

If a user searches and no results are returned, the pagination links disappear and instead the div displays “No entries found”.

Here’s how to do that:

  <% if @users.blank? %>
    <%= page_entries_info @users %>
  <% else %>
    <%= will_paginate @users %>
  <% end %>

Simple but clean. Always keep in mind relevance when it comes to developing your apps and designing your interfaces. If you can hide irrelevant information from a user, it makes your application that much easier to use.

ONE FEEDBACK

  1. Steve says:

    Wow, never thought of that. Sweet.

LEAVE A COMMENT