add tag seq nav

This commit is contained in:
albert
2013-02-25 12:09:02 -05:00
parent 2aa141aa69
commit c6d03f2d3a
10 changed files with 81 additions and 13 deletions

View File

@@ -0,0 +1,25 @@
class PostSearchContext
attr_reader :params, :post_id
def initialize(params)
@params = params
raise unless params[:seq].present?
raise unless params[:id].present?
@post_id = find_post_id
end
def find_post_id
if params[:seq] == "prev"
post = Post.tag_match(params[:tags]).where("posts.id > ?", params[:id].to_i).reorder("posts.id asc").first
else
post = Post.tag_match(params[:tags]).where("posts.id < ?", params[:id].to_i).reorder("posts.id desc").first
end
if post
post.id
else
nil
end
end
end