diff --git a/app/controllers/concerns/search/query_terms_scoped.rb b/app/controllers/concerns/search/query_terms_scoped.rb new file mode 100644 index 000000000..11b88cdf2 --- /dev/null +++ b/app/controllers/concerns/search/query_terms_scoped.rb @@ -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 diff --git a/app/controllers/searches/queries_controller.rb b/app/controllers/searches/queries_controller.rb index 6e7aa055d..f6b474baa 100644 --- a/app/controllers/searches/queries_controller.rb +++ b/app/controllers/searches/queries_controller.rb @@ -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 diff --git a/app/controllers/searches_controller.rb b/app/controllers/searches_controller.rb index 6441b7592..8af152344 100644 --- a/app/controllers/searches_controller.rb +++ b/app/controllers/searches_controller.rb @@ -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 diff --git a/app/views/searches/_form.html.erb b/app/views/searches/_form.html.erb index 8653aa1df..8238a7e85 100644 --- a/app/views/searches/_form.html.erb +++ b/app/views/searches/_form.html.erb @@ -1,4 +1,3 @@ - <%= form_with url: search_path, method: :get, class: "search__form" do |form| %>
<%= text_field_tag :q, query_terms, class: "input", type: "search", placeholder: "What are you looking for?" %> diff --git a/app/views/searches/show.html.erb b/app/views/searches/show.html.erb index e9b2f3890..7cd475f63 100644 --- a/app/views/searches/show.html.erb +++ b/app/views/searches/show.html.erb @@ -12,7 +12,7 @@ <% 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 %>