Skip to content

Commit

Permalink
Fix search page, result item nil error.
Browse files Browse the repository at this point in the history
  • Loading branch information
huacnlee committed Oct 16, 2023
1 parent b1237a8 commit b677fdd
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 15 deletions.
16 changes: 7 additions & 9 deletions app/views/search/_topic.html.erb
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
<% if item %>
<div class="result">
<div class="title"><%= link_to highlight(item.title, terms: @search.terms), item %></div>
<div class="info">
<span class="url"><%= link_to polymorphic_url(item), item %></span>
<span class="date" title="Last Updated At"><%= item.created_at.to_date %></span>
</div>
<div class="desc"><%= highlight(hit.hit_content, terms: @search.terms) %></div>
<div class="result">
<div class="title"><%= link_to highlight(item.title, terms: @search.terms), item %></div>
<div class="info">
<span class="url"><%= link_to polymorphic_url(item), item %></span>
<span class="date" title="Last Updated At"><%= item.created_at.to_date %></span>
</div>
<% end %>
<div class="desc"><%= highlight(hit.hit_content, terms: @search.terms) %></div>
</div>
7 changes: 4 additions & 3 deletions app/views/search/_user.html.erb
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
<% if item.organization? %>
<%= render 'team', item: item, hit: hit %>
<% else %>

<div class="result user media">
<div class="media">
<div class="avatar media-left mr-3">
<div class="mr-3 avatar media-left">
<div class='image'><%= user_avatar_tag(item, :md) %></div>
</div>
<div class="media-body">
Expand All @@ -14,10 +15,10 @@
<div class="info number">
<span title="Created At"><%= item.created_at.to_date %></span>
<% if item.location.present? %><span title="Location"><%= location_name_tag(item.location) %></span><% end %>
<span><%= item.topics_count %></span> Topics • <span><%= item.replies_count %></span> Replies
</div>
</div>
</div>
</div>
<% end %>
<% end %>
8 changes: 5 additions & 3 deletions app/views/search/index.html.erb
Original file line number Diff line number Diff line change
@@ -1,16 +1,18 @@
<% title_tag [params[:q], t('common.search_result')].join(' · ') %>
<div class="search-results card card-lg">
<div class="card-body">
<div class="card-title clearfix">
Search result of: <%= params[:q] %>
<div class="flex justify-between card-title">
<div>Search result of: <b><%=params[:q] %></b></div>
<div class="counter">Total <%= @result.count %> records</div>
</div>
<% if @result.count == 0 %>
<div class="no-result">Can not find anything about: <%= params[:q]%></div>
<% else %>
<% @result.each do |doc| %>
<% partial_view_name = doc.searchable_type.downcase -%>
<%= render partial: (partial_view_name == 'team' ? 'user' : partial_view_name), locals: { item: doc.searchable, hit: doc } %>
<% if doc.searchable %>
<%= render partial: (partial_view_name == 'team' ? 'user' : partial_view_name), locals: { item: doc.searchable, hit: doc } %>
<% end %>
<% end %>
<% end %>
<%= paginate @result %>
Expand Down

0 comments on commit b677fdd

Please sign in to comment.