Move queries to its own resource

This commit is contained in:
Jorge Manrubia
2025-06-24 12:17:08 +02:00
parent e1d643cebd
commit dfd52fc946
8 changed files with 24 additions and 10 deletions
@@ -0,0 +1,11 @@
class Searches::QueriesController < ApplicationController
def create
Current.user.remember_search(terms_params)
head :ok
end
private
def terms_params
params[:terms]
end
end
-5
View File
@@ -1,9 +1,4 @@
class SearchesController < ApplicationController
def create
Current.user.remember_search(query_param)
head :ok
end
def show
@search_results = Current.user.search(query_param).limit(50)
@recent_search_queries = Current.user.search_queries.order(created_at: :desc).limit(10)
+5 -1
View File
@@ -3,6 +3,10 @@ module FormsHelper
data = attributes.delete(:data) || {}
data[:controller] = "auto-submit #{data[:controller]}".strip
form_with **attributes, data: data, &
if block_given?
form_with **attributes, data: data, &
else
form_with(**attributes, data: data) { }
end
end
end
+1 -1
View File
@@ -11,7 +11,7 @@ class Search
end
def results
return [] unless query.valid?
return Search::Result.none unless query.valid?
cards = user.accessible_cards.search(query)
.select([
+1 -1
View File
@@ -16,7 +16,7 @@ class Search::Query < ApplicationRecord
private
def sanitize_query_syntax
self.terms = begin
self.terms = if terms.present?
terms = remove_invalid_search_characters(self.terms)
terms = remove_unbalanced_quotes(terms)
terms.presence
+1
View File
@@ -1,3 +1,4 @@
<%= form_with url: search_path, method: :get, class: "search__form" do |form| %>
<div class="search__field">
<%= text_field_tag :q, params[:q], class: "input", type: "search", placeholder: "What are you looking for?" %>
+2 -2
View File
@@ -12,11 +12,11 @@
</nav>
<% end %>
<%= auto_submit_form_with url: searches_queries_path(terms: params[:q]), method: :post %>
<section class="search">
<%= render "searches/form" %>
<%= auto_submit_form_with url: search_path(q: params[:q]), method: :post %>
<ul class="search__list">
<%= render partial: "searches/result", collection: @search_results %>
</ul>
+3
View File
@@ -62,6 +62,9 @@ Rails.application.routes.draw do
end
resource :search
namespace :searches do
resources :queries
end
resources :filters