Find which page an item is on
-
Chris Wanstrath
Here's how I did it once:
def self.page_for_pagination(id, per_page = 10) return if (id = id.to_i) < 1 query = "SELECT id FROM %s ORDER BY id DESC" % table_name find_by_sql(query).map(&:id).index(id).to_i / per_page + 1 endIf we extract pagination logic, we could slide through a window of 200 rows or something trying to find the id...
-
Mislav
- Milestone set to will_paginate v3.0 ("agnostic")
- Tag set to will_paginate
Please Sign in or create a free account to add a new ticket.
With your very own profile, you can contribute to projects, track your activity, watch tickets, receive and update tickets through your email and much more.