From 6329d089ee2d7fe3404245c8e57bec5c9bf59141 Mon Sep 17 00:00:00 2001 From: evazion Date: Thu, 22 Jun 2017 16:50:25 -0500 Subject: [PATCH] post replacements: add tag match field to search form. --- app/models/post_replacement.rb | 8 ++++++++ app/views/post_replacements/index.html.erb | 1 + 2 files changed, 9 insertions(+) diff --git a/app/models/post_replacement.rb b/app/models/post_replacement.rb index 474247d61..b41c314de 100644 --- a/app/models/post_replacement.rb +++ b/app/models/post_replacement.rb @@ -69,6 +69,10 @@ class PostReplacement < ApplicationRecord end module SearchMethods + def post_tags_match(query) + PostQueryBuilder.new(query).build(self.joins(:post)) + end + def search(params = {}) q = all @@ -88,6 +92,10 @@ class PostReplacement < ApplicationRecord q = q.where(post_id: params[:post_id].split(",").map(&:to_i)) end + if params[:post_tags_match].present? + q = q.post_tags_match(params[:post_tags_match]) + end + q = q.order("created_at DESC") q diff --git a/app/views/post_replacements/index.html.erb b/app/views/post_replacements/index.html.erb index ce84f0af1..b1cfaa87f 100644 --- a/app/views/post_replacements/index.html.erb +++ b/app/views/post_replacements/index.html.erb @@ -6,6 +6,7 @@ <%= simple_form_for(:search, url: post_replacements_path, method: :get, defaults: { required: false }, html: { class: "inline-form" }) do |f| %> <%= f.input :creator_name, label: "Replacer", input_html: { value: params[:search][:creator_name] } %> + <%= f.input :post_tags_match, label: "Tags", input_html: { value: params[:search][:post_tags_match] } %> <%= f.submit "Search" %> <% end %>