Skip to content

Instantly share code, notes, and snippets.

@komasaru
Last active December 11, 2015 12:38
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 komasaru/4601648 to your computer and use it in GitHub Desktop.
Save komasaru/4601648 to your computer and use it in GitHub Desktop.
Ruby script to generate pager for each article.
# Previous(Older) article
def prev_link
prv = sorted_articles.index(@item) + 1
unless articles.size - 1 < prv
link_to(
'&laquo;[Older] ' + sorted_articles[prv][:title],
sorted_articles[prv].reps[0],
:class => "prev"
)
end
end
# Next(Newer) article
def next_link
nxt = sorted_articles.index(@item) - 1
unless nxt < 0
link_to(
sorted_articles[nxt][:title] + ' [Newer]&raquo;',
sorted_articles[nxt].reps[0],
:class => "next"
)
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment