Skip to content

Instantly share code, notes, and snippets.

@Olli
Created August 29, 2018 13:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Olli/2ef29c60a6c16cd9a0c2045fb960f85b to your computer and use it in GitHub Desktop.
Save Olli/2ef29c60a6c16cd9a0c2045fb960f85b to your computer and use it in GitHub Desktop.
will_paginate and SEO prev next head link tags
#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