Use form builder for search form

This commit is contained in:
Lars Henrik Mai 2015-10-10 07:45:30 +02:00
parent 19616d215e
commit 7d2314fb6d
3 changed files with 12 additions and 16 deletions

View file

@ -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

View file

@ -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

View file

@ -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