refactoring
This commit is contained in:
@@ -36,6 +36,14 @@ module PostSets
|
||||
@page ||= params[:page] ? params[:page].to_i : 1
|
||||
end
|
||||
|
||||
def total_pages
|
||||
(count / limit.to_f).ceil
|
||||
end
|
||||
|
||||
def current_page
|
||||
page
|
||||
end
|
||||
|
||||
def offset
|
||||
((page < 1) ? 0 : (page - 1)) * limit
|
||||
end
|
||||
|
||||
@@ -41,6 +41,10 @@ module PostSets
|
||||
@tag_array ||= ::Tag.scan_query(tag_string)
|
||||
end
|
||||
|
||||
def tags
|
||||
tag_array
|
||||
end
|
||||
|
||||
def validate
|
||||
super
|
||||
validate_query_count
|
||||
|
||||
@@ -18,6 +18,22 @@ module PostSets
|
||||
end
|
||||
end
|
||||
|
||||
def first_id
|
||||
if posts.any?
|
||||
posts.first.id
|
||||
else
|
||||
nil
|
||||
end
|
||||
end
|
||||
|
||||
def last_id
|
||||
if posts.any?
|
||||
posts.last.id
|
||||
else
|
||||
nil
|
||||
end
|
||||
end
|
||||
|
||||
def pagination_options
|
||||
{:before_id => before_id, :after_id => after_id}
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user