From e4c908d4b4a4a8f681a1015083ad61fb2d4f4c4e Mon Sep 17 00:00:00 2001 From: David Backeus Date: Wed, 3 May 2023 11:50:51 +0200 Subject: [PATCH] Add Search UI --- app/controllers/search_controller.rb | 5 +++++ app/views/layouts/application.html.erb | 1 + app/views/search/index.html.erb | 16 ++++++++++++++++ config/routes.rb | 3 ++- 4 files changed, 24 insertions(+), 1 deletion(-) create mode 100644 app/controllers/search_controller.rb create mode 100644 app/views/search/index.html.erb diff --git a/app/controllers/search_controller.rb b/app/controllers/search_controller.rb new file mode 100644 index 0000000..cec1619 --- /dev/null +++ b/app/controllers/search_controller.rb @@ -0,0 +1,5 @@ +class SearchController < ApplicationController + def index + @results = Elasticsearch.search(params[:query]) + end +end diff --git a/app/views/layouts/application.html.erb b/app/views/layouts/application.html.erb index 79f29b8..06e5cdb 100644 --- a/app/views/layouts/application.html.erb +++ b/app/views/layouts/application.html.erb @@ -14,6 +14,7 @@ <%= yield %> diff --git a/app/views/search/index.html.erb b/app/views/search/index.html.erb new file mode 100644 index 0000000..d8f6087 --- /dev/null +++ b/app/views/search/index.html.erb @@ -0,0 +1,16 @@ +

Search

+ +<%= form_with url: search_path, method: :get do |form| %> + <%= form.label :query %> + <%= form.text_field :query, value: params[:query], autofocus: true %> + <%= form.submit "Search" %> +<% end %> + +<% if @results.present? %> +

Results

+ +<% end %> \ No newline at end of file diff --git a/config/routes.rb b/config/routes.rb index 82f0548..c08d83d 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -1,7 +1,8 @@ Rails.application.routes.draw do resources :links resources :posts - # Define your application routes per the DSL in https://guides.rubyonrails.org/routing.html + + get "search" => "search#index", as: :search # Reveal health status on /up that returns 200 if the app boots with no exceptions, otherwise 500. # Can be used by load balancers and uptime monitors to verify that the app is live.