Skip to content

Instantly share code, notes, and snippets.

@reu
Created February 12, 2011 14:45
Show Gist options
  • Save reu/823799 to your computer and use it in GitHub Desktop.
Save reu/823799 to your computer and use it in GitHub Desktop.
scope :page, lambda { |number|
per_page = 2
limit(per_page).offset(per_page * ([number.to_i, 1].max - 1))
} do
def per(number)
limit(number).offset(offset_value / limit_value * number)
end
def num_pages
(except(:offset, :limit).count.to_f / limit_value).ceil
end
def current_page
offset_value / limit_value + 1
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment