Skip to content

Instantly share code, notes, and snippets.

@pjbelo
Last active September 7, 2018 15:23
Show Gist options
  • Save pjbelo/7f7dc0619ff12600da9b064831fb6929 to your computer and use it in GitHub Desktop.
Save pjbelo/7f7dc0619ff12600da9b064831fb6929 to your computer and use it in GitHub Desktop.
Using Pagy gem with Rails and Bootstrap
Include in gemfile:
gem 'pagy'
for global access, include in application_controller.rb:
include Pagy::Backend
and in application_helper.rb:
include Pagy::Frontend
In controller (eg. BlogPosts), where items define number of items per page:
@pagy, @blog_posts = pagy(BlogPost.all, items: 20)
In the View render the navigation links:
<%= pagy_nav_bootstrap(@pagy).html_safe %>
or
<%== pagy_nav_bootstrap(@pagy) %>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment