Ruby Rails: How to add numeric pagination.

Perhaps you are still using the default rails pagination which appears as two links at the bottom of your page ‘Previous page’ and ‘Next page’. If you would like to alter this and be able to access any page instantly you could add the following code into your list.rhtml file:

< %
#here we add the code for enumeration of all available pages
numpage = 1
for a_page in @cert_incident_pages
if a_page == @cert_incident_pages.current
% >
< %= link_to '['+numpage.to_s+']', { :page => a_page } %>
< % else %>
< %= link_to numpage.to_s, { :page => a_page } %>
< %
end
numpage = numpage + 1
end
%>

Don’t forget to change the ‘@person_pages’ to correspond to your variable which is defined in your controller’s list method. Of course you can now remove the ‘link_to’ lines that render ‘Previous page’ and ‘Next page’.

That’s all for now and stay tuned for more code snippets and of course the new release of Firebolt.