From fc0da456cb2932050d8cb1be5c3c7faf97b0387e Mon Sep 17 00:00:00 2001 From: James Smith Date: Sun, 17 Jul 2022 22:24:53 +0100 Subject: [PATCH] Add links to recently-added models on search page --- app/controllers/search_controller.rb | 2 ++ app/views/search/index.html.erb | 16 ++++++++++++++++ 2 files changed, 18 insertions(+) diff --git a/app/controllers/search_controller.rb b/app/controllers/search_controller.rb index d3e635c9c..1930e1c32 100644 --- a/app/controllers/search_controller.rb +++ b/app/controllers/search_controller.rb @@ -8,6 +8,8 @@ def index @results = Model.where(field.matches("%#{@query}%")) @results += Model.tagged_with(@query) @results.uniq! + else + @recent = Model.order(created_at: :desc).limit(20) end end diff --git a/app/views/search/index.html.erb b/app/views/search/index.html.erb index 41215d692..ef47630b5 100644 --- a/app/views/search/index.html.erb +++ b/app/views/search/index.html.erb @@ -25,3 +25,19 @@ Search for more on Yeggi <% end %> +<% if @recent %> +
+
+

Recently-added Models

+ + <% @recent.each do |model| %> + + + + + + <% end %> +
<%= link_to model.name, library_model_path(model.library, model) %><%= link_to model.library.name, model.library %><%= time_ago_in_words(model.created_at) %> ago
+
+
+<% end %>