Created
July 11, 2013 13:02
-
-
Save pironim/5975256 to your computer and use it in GitHub Desktop.
Kaminary find page for id
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
# You should sort by uniq column to make your results predictable | |
def pagination_base | |
current_company.projects.order('name ASC, id ASC') | |
end | |
def page_for(id) | |
ids = pagination_base.pluck(:id) | |
position = ids.index(id.to_i) | |
((position+1).to_f/PER_PAGE.to_f).ceil | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment