diff --git a/app/controllers/logs_controller.rb b/app/controllers/logs_controller.rb index e63b34e..cedc8d4 100644 --- a/app/controllers/logs_controller.rb +++ b/app/controllers/logs_controller.rb @@ -2,6 +2,13 @@ class LogsController < ApplicationController before_action :authenticate_user! def index - @logs = Log.paginate(page: params[:page], per_page: 20) + logs = Log + + if params[:search].present? + logger.debug "Searching for #{params[:search]}" + logs = logs.where("message ilike ?", "%#{params[:search]}%") + end + + @logs = logs.paginate(page: params[:page], per_page: 20) end end diff --git a/app/views/logs/index.html.slim b/app/views/logs/index.html.slim index c37aa39..64db410 100644 --- a/app/views/logs/index.html.slim +++ b/app/views/logs/index.html.slim @@ -6,7 +6,8 @@ .small-6.medium-4.large-3.columns // Search form - = render 'packages/searchfield' + = form_tag url_for, :method=>'GET' + = text_field_tag(:search, params[:search], placeholder: "Search...", maxlength: 50, size: 20, autofocus: true) // List of log messages .row @@ -20,7 +21,7 @@ th =log.created_at th =log.message - else - p No logs. Crazy. + p No logs found. Crazy. - // Second paginator at the bottom so the user does not have to scroll up again + // Second paginator at the bottom so the user does not have to scroll up again = render 'logs/paginator'