Created
February 12, 2011 14:45
-
-
Save reu/823799 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
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