diff --git a/app/controllers/searches_controller.rb b/app/controllers/searches_controller.rb index 2fba80b35..6441b7592 100644 --- a/app/controllers/searches_controller.rb +++ b/app/controllers/searches_controller.rb @@ -1,11 +1,13 @@ class SearchesController < ApplicationController + before_action :set_query_terms + def show - @search_results = Current.user.search(query_param).limit(50) + @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 query_param - params[:q] + 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 69797e99a..8653aa1df 100644 --- a/app/views/searches/_form.html.erb +++ b/app/views/searches/_form.html.erb @@ -1,7 +1,7 @@ <%= form_with url: search_path, method: :get, class: "search__form" do |form| %>
- <%= text_field_tag :q, params[:q], class: "input", type: "search", placeholder: "What are you looking for?" %> + <%= text_field_tag :q, query_terms, class: "input", type: "search", placeholder: "What are you looking for?" %> <%= icon_tag "search" %> diff --git a/app/views/searches/show.html.erb b/app/views/searches/show.html.erb index df58583be..e9b2f3890 100644 --- a/app/views/searches/show.html.erb +++ b/app/views/searches/show.html.erb @@ -12,12 +12,12 @@ <% end %> -<%= auto_submit_form_with url: searches_queries_path(terms: params[:q]), method: :post %> +<%= auto_submit_form_with url: searches_queries_path(terms: @query_terms), method: :post %>