Extract query_terms to an instance variable
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
|
||||
<%= 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?" %>
|
||||
<%= text_field_tag :q, query_terms, class: "input", type: "search", placeholder: "What are you looking for?" %>
|
||||
<span class="search__field-icon btn btn--circle borderless">
|
||||
<%= icon_tag "search" %>
|
||||
</span>
|
||||
|
||||
@@ -12,12 +12,12 @@
|
||||
</nav>
|
||||
<% 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 %>
|
||||
|
||||
<section class="search">
|
||||
<%= render "searches/form" %>
|
||||
<%= render "searches/form", query_terms: @query_terms %>
|
||||
|
||||
<% if params[:q].present? && @search_results.none? %>
|
||||
<% if @query_terms.present? && @search_results.none? %>
|
||||
<p>No search results</p>/
|
||||
<% end %>
|
||||
|
||||
|
||||
Reference in New Issue
Block a user