Skip to content

Instantly share code, notes, and snippets.

@zandroid
Last active September 26, 2017 21:55
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save zandroid/8ed85b518fd3ce441f0864477aa7eb86 to your computer and use it in GitHub Desktop.
Save zandroid/8ed85b518fd3ce441f0864477aa7eb86 to your computer and use it in GitHub Desktop.
This is a custom link renderer that will format the pagination bar with Bootstrap4
module PaginateHelper
class LinkRenderer < WillPaginate::ActionView::LinkRenderer
protected
def html_container(html)
tag(:nav, tag(:ul, html, class: "pagination"))
end
def previous_or_next_page(page, text, classname)
if page
tag(:li, link(text, page, class: "page-link"), class: "page-item")
else
tag(:li, tag(:a, text, class: "page-link"), class: "page-item disabled")
end
end
def page_number(page)
unless page == current_page
tag(:li, link(page, page, class: "page-link"), class: "page-item")
else
tag(:li, tag(:a, page, class: "page-link"), class: "page-item active")
end
end
def gap
tag(:li, tag(:a, '&hellip;', class: "page-link"), class: "page-item disabled")
end
end ## end of class
def bs_will_paginate(collection = nil, options = {})
options, collection = collection, nil if collection.is_a? Hash
options = options.merge(
renderer: PaginateHelper::LinkRenderer,
previous_label: "&laquo;",
next_label: "&raquo;"
)
will_paginate(collection, options)
end
end
@zandroid
Copy link
Author

zandroid commented Oct 9, 2016

Example of usage: just bs_will_paginate or bs_will_paginate @users

@chdezmar
Copy link

chdezmar commented Dec 21, 2016

Thanks! It works perfectly.

@christianroy
Copy link

Works great! 👍 Thanks!

@creedian
Copy link

Great work!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment