From c0befbd02559591b0c2871ea9cef1e4d913b9ef6 Mon Sep 17 00:00:00 2001 From: Miquel Sabaté Solà Date: Mon, 11 Nov 2024 22:45:05 +0100 Subject: Allow searching from a given tag MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This feature is useful if you want to have a quick search on how many resources apply for a single tag. Signed-off-by: Miquel Sabaté Solà --- app/controllers/tags_controller.rb | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) (limited to 'app/controllers') diff --git a/app/controllers/tags_controller.rb b/app/controllers/tags_controller.rb index ee837ef..c5ca6a8 100644 --- a/app/controllers/tags_controller.rb +++ b/app/controllers/tags_controller.rb @@ -1,7 +1,7 @@ # frozen_string_literal: true class TagsController < ApplicationController - before_action :set_tag, only: %i[edit update destroy] + before_action :set_tag, only: %i[edit update destroy search] def index @tags = Tag.order(:name) @@ -57,10 +57,16 @@ class TagsController < ApplicationController redirect_to tags_url, notice: t('tags.destroy-success') end + def search + @search = Search.new(name: 'temporary', body: "tag:\"#{@tag.name}\"") + + render 'searches/show' + end + private def set_tag - @tag = Tag.find(params[:id]) + @tag = Tag.find(params[:id] || params[:tag_id]) end def tag_params -- cgit v1.2.3