Skip to content

Commit 4569606

Browse files
authored
Merge pull request #599 from Floppy/recently-added
Add links to recently-added models on search page
2 parents f148a4e + fc0da45 commit 4569606

File tree

2 files changed

+18
-0
lines changed

2 files changed

+18
-0
lines changed

app/controllers/search_controller.rb

+2
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ def index
88
@results = Model.where(field.matches("%#{@query}%"))
99
@results += Model.tagged_with(@query)
1010
@results.uniq!
11+
else
12+
@recent = Model.order(created_at: :desc).limit(20)
1113
end
1214
end
1315

app/views/search/index.html.erb

+16
Original file line numberDiff line numberDiff line change
@@ -25,3 +25,19 @@
2525
<a href='https://yeggi.com/q/<%= @query %>/'>Search for more on Yeggi</a>
2626
</div>
2727
<% end %>
28+
<% if @recent %>
29+
<div class="row row-cols-2">
30+
<div class="col-8 offset-md-2">
31+
<p class="lead">Recently-added Models</p>
32+
<table class="table">
33+
<% @recent.each do |model| %>
34+
<tr>
35+
<td><%= link_to model.name, library_model_path(model.library, model) %></td>
36+
<td><%= link_to model.library.name, model.library %></td>
37+
<td><%= time_ago_in_words(model.created_at) %> ago</td>
38+
</tr>
39+
<% end %>
40+
</table>
41+
</div>
42+
</div>
43+
<% end %>

0 commit comments

Comments
 (0)