Created
August 29, 2018 13:24
-
-
Save Olli/2ef29c60a6c16cd9a0c2045fb960f85b to your computer and use it in GitHub Desktop.
will_paginate and SEO prev next head link tags
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#put it into one of your app/helpers files | |
# you have to replace the collection_path with the path of your model! | |
# tag.link only works from rails 5.1 ... prior you have to use content_tag ... | |
# next - prev links header | |
def pagination_head_tags(collection) | |
if collection.total_pages | |
link_tags = "" | |
if collection.current_page < collection.total_pages | |
link_tags += tag.link nil, href: collection_path(page: collection.current_page + 1), rel: "next" | |
end | |
if collection.current_page > 1 | |
link_tags += tag.link href: collection_path(page: collection.current_page - 1), rel: "prev" | |
end | |
link_tags.html_safe | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment