From bf776ce55e475a06175f5bd095a48c88def4df57 Mon Sep 17 00:00:00 2001 From: Guillaume Dott Date: Fri, 13 Nov 2015 12:38:49 +0100 Subject: [PATCH] Add search link when no results are found on index --- lib/librarix/helpers.rb | 4 ++++ lib/librarix/views/index.slim | 6 ++++++ 2 files changed, 10 insertions(+) diff --git a/lib/librarix/helpers.rb b/lib/librarix/helpers.rb index e13e285..972ad43 100644 --- a/lib/librarix/helpers.rb +++ b/lib/librarix/helpers.rb @@ -7,5 +7,9 @@ module Librarix 'default' end end + + def maybe_search?(movies) + movies.empty? && params.key?('title') + end end end diff --git a/lib/librarix/views/index.slim b/lib/librarix/views/index.slim index c3a524f..91471b7 100644 --- a/lib/librarix/views/index.slim +++ b/lib/librarix/views/index.slim @@ -17,3 +17,9 @@ form method="get" action="/" id="filter" == slim :list, locals: {movies: movies} +- if maybe_search?(movies) + p + | Search for + strong + a<> href="#{url("/search?search=#{params['title']}")}" = params['title'] + | ?