Model#search: factor out post_tags_match.

This commit is contained in:
evazion
2019-08-29 16:44:19 -05:00
parent c3ad7f6112
commit 6fc4b63fa8
9 changed files with 27 additions and 104 deletions

View File

@@ -121,6 +121,20 @@ class ApplicationRecord < ActiveRecord::Base
end
end
def search_post_id_attribute(params)
relation = self
if params[:post_id].present?
relation = relation.attribute_matches(:post_id, params[:post_id])
end
if params[:post_tags_match].present?
relation = relation.where(post_id: Post.tag_match(params[:post_tags_match]).reorder(nil))
end
relation
end
def apply_default_order(params)
if params[:order] == "custom"
parse_ids = Tag.parse_helper(params[:id])