From a4b4c81f8d6cab6c0fa5198ffbfa56270ead6587 Mon Sep 17 00:00:00 2001 From: Lars Henrik Mai Date: Sat, 10 Oct 2015 07:45:30 +0200 Subject: [PATCH] Use form builder for search form --- app/controllers/search_controller.rb | 8 ++------ app/helpers/search_helper.rb | 8 ++++---- app/views/search/_form.slim | 12 ++++++------ 3 files changed, 12 insertions(+), 16 deletions(-) diff --git a/app/controllers/search_controller.rb b/app/controllers/search_controller.rb index d31861d..b5e2b48 100644 --- a/app/controllers/search_controller.rb +++ b/app/controllers/search_controller.rb @@ -7,12 +7,8 @@ end class SearchController < ApplicationController def index - @search_definition = PaperSearch.new(query: params[:q], - paper_type: params[:paper_type], - originator: params[:originator], - sort_by: params[:paper_search][:sort_by]) - - # @search = PaperSearch.new params[:paper_search] + @search_definition = PaperSearch.new(params[:paper_search]) + @search_definition.sort_by ||= "score" @response = Paper.search(@search_definition) @papers = @response.page(params[:page]).results diff --git a/app/helpers/search_helper.rb b/app/helpers/search_helper.rb index 908199c..6da0a1b 100644 --- a/app/helpers/search_helper.rb +++ b/app/helpers/search_helper.rb @@ -11,14 +11,14 @@ module SearchHelper end end - def filter_select(name, desc, facets, selected) + def filter_select(builder, name, desc, facets, selected) capture do concat(label name, desc) concat( - select_tag name, + builder.select name, options_from_collection_for_select(facets, :term, :term_with_count, selected), - include_blank: true, - onchange: "this.form.submit();" + { include_blank: true }, + { onchange: "this.form.submit();" } ) end end diff --git a/app/views/search/_form.slim b/app/views/search/_form.slim index 34c0f49..d153699 100644 --- a/app/views/search/_form.slim +++ b/app/views/search/_form.slim @@ -1,15 +1,15 @@ -= form_for(@search_definition, url: search_path, method: :get) do |f| - = text_field_tag(:q, @search_definition.query, placeholder: 'Suche…', autofocus: true) += form_for @search_definition, url: search_path, method: :get do |f| + = f.text_field :query, placeholder: 'Suche…', autofocus: true fieldset legend Ergebnisse filtern .row .small-4.columns - = filter_select("paper_type", "Typ", @paper_type_facets, @search_definition.paper_type) + = filter_select(f, "paper_type", "Typ", @paper_type_facets, @search_definition.paper_type) .small-4.columns - = filter_select("originator", "Einreicher", @originator_facets, @search_definition.originator) + = filter_select(f, "originator", "Einreicher", @originator_facets, @search_definition.originator) .small-4.columns.end label Sortierung - = f.radio_button :sort_by, :date + = f.radio_button :sort_by, :date, onchange: "this.form.submit();" label for="sort_by_date" Nach Datum - = f.radio_button :sort_by, :score + = f.radio_button :sort_by, :score, onchange: "this.form.submit();" label for="sort_by_score" Nach Relevanz