diff --git a/app/controllers/searches/queries_controller.rb b/app/controllers/searches/queries_controller.rb new file mode 100644 index 000000000..6e7aa055d --- /dev/null +++ b/app/controllers/searches/queries_controller.rb @@ -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 diff --git a/app/controllers/searches_controller.rb b/app/controllers/searches_controller.rb index d32e3fba9..2fba80b35 100644 --- a/app/controllers/searches_controller.rb +++ b/app/controllers/searches_controller.rb @@ -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) diff --git a/app/helpers/forms_helper.rb b/app/helpers/forms_helper.rb index 3220d2d78..095655e3b 100644 --- a/app/helpers/forms_helper.rb +++ b/app/helpers/forms_helper.rb @@ -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 diff --git a/app/models/search.rb b/app/models/search.rb index 06e1571ae..ea682b8fe 100644 --- a/app/models/search.rb +++ b/app/models/search.rb @@ -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([ diff --git a/app/models/search/query.rb b/app/models/search/query.rb index 122a1d90c..7e9a0fb8d 100644 --- a/app/models/search/query.rb +++ b/app/models/search/query.rb @@ -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 diff --git a/app/views/searches/_form.html.erb b/app/views/searches/_form.html.erb index 8bbcf9483..69797e99a 100644 --- a/app/views/searches/_form.html.erb +++ b/app/views/searches/_form.html.erb @@ -1,3 +1,4 @@ + <%= form_with url: search_path, method: :get, class: "search__form" do |form| %>