Extract common concern

This commit is contained in:
Jorge Manrubia
2025-06-24 12:45:15 +02:00
parent 96c9a95a18
commit 2821cf9850
5 changed files with 17 additions and 14 deletions
@@ -0,0 +1,12 @@
module Search::QueryTermsScoped
extend ActiveSupport::Concern
included do
before_action :set_query_terms
end
private
def set_query_terms
@query_terms = params[:q]
end
end
@@ -1,11 +1,8 @@
class Searches::QueriesController < ApplicationController
include Search::QueryTermsScoped
def create
Current.user.remember_search(terms_params)
Current.user.remember_search(@query_terms)
head :ok
end
private
def terms_params
params[:terms]
end
end
+1 -6
View File
@@ -1,13 +1,8 @@
class SearchesController < ApplicationController
before_action :set_query_terms
include Search::QueryTermsScoped
def show
@search_results = Current.user.search(@query_terms).limit(50)
@recent_search_queries = Current.user.search_queries.order(created_at: :desc).limit(10)
end
private
def set_query_terms
@query_terms = params[:q]
end
end
-1
View File
@@ -1,4 +1,3 @@
<%= form_with url: search_path, method: :get, class: "search__form" do |form| %>
<div class="search__field">
<%= text_field_tag :q, query_terms, class: "input", type: "search", placeholder: "What are you looking for?" %>
+1 -1
View File
@@ -12,7 +12,7 @@
</nav>
<% end %>
<%= auto_submit_form_with url: searches_queries_path(terms: @query_terms), method: :post %>
<%= auto_submit_form_with url: searches_queries_path(q: @query_terms), method: :post %>
<section class="search">
<%= render "searches/form", query_terms: @query_terms %>