views:

40

answers:

1

I'm using will_paginate as standard, but it only shows the pagination controls (< 1 2 > etc) when there's more than one page to display. Normally, this would be what is wanted, but I want to see the pagination controls (for UI consistency and to get round an annoying CSS quirk in the system I'm working on) even when there's only 1 page to display (showing < 1 >).

Is this possible?

+2  A: 

The default will_paginate helper returns nil when there is only one page, so you could do something like this:

<%= will_paginate(@records) || your_single_page_state_html %>
Jimmy Cuadra
This feels a little dirty to me -- possibly because it needs to be repeated for each page that has pagination. Unfortunately, it is really the only good solution. WillPaginate makes its determination to render based on `WillPaginate::ViewHelpers.total_pages_for_collection`, which you can't change without adversely affecting the behavior of the plugin. I guess if you need to do this for lots of paginated pages, you might extract it into a helper method: `def paginate_always(records); will_paginate(records) || some_html; end`.
James A. Rosen
That's a cleaner way to do this - thanks very much! :)
James Inman