/iqdb_queries: include full data for each post in api response.
This commit is contained in:
@@ -33,7 +33,13 @@ module Iqdb
|
|||||||
if resp.is_a?(Net::HTTPSuccess)
|
if resp.is_a?(Net::HTTPSuccess)
|
||||||
json = JSON.parse(resp.body)
|
json = JSON.parse(resp.body)
|
||||||
if json.is_a?(Array)
|
if json.is_a?(Array)
|
||||||
@matches = json
|
post_ids = json.map { |match| match["post_id"] }
|
||||||
|
posts = Post.find(post_ids)
|
||||||
|
|
||||||
|
@matches = json.map do |match|
|
||||||
|
post = posts.find { |post| post.id == match["post_id"] }
|
||||||
|
match.with_indifferent_access.merge({ post: post })
|
||||||
|
end
|
||||||
else
|
else
|
||||||
@matches = []
|
@matches = []
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
var html = '';
|
var html = '';
|
||||||
<% if @results.any? %>
|
<% if @results.any? %>
|
||||||
<% @results.each do |match| %>
|
<% @results.each do |match| %>
|
||||||
html += '<%= j PostPresenter.preview(Post.find(match["post_id"]), :tags => "status:any") %>';
|
html += '<%= j PostPresenter.preview(match[:post], :tags => "status:any") %>';
|
||||||
<% end %>
|
<% end %>
|
||||||
<% else %>
|
<% else %>
|
||||||
html += '<p>No matches found</p>';
|
html += '<p>No matches found</p>';
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
<% if @results.any? %>
|
<% if @results.any? %>
|
||||||
<h3>Similar</h3>
|
<h3>Similar</h3>
|
||||||
<% @results.each do |match| %>
|
<% @results.each do |match| %>
|
||||||
<%= PostPresenter.preview(Post.find(match["post_id"]), :tags => "status:any", :size => true) %>
|
<%= PostPresenter.preview(match[:post], :tags => "status:any", :size => true) %>
|
||||||
<% end %>
|
<% end %>
|
||||||
<% else %>
|
<% else %>
|
||||||
<h3>Similar</h3>
|
<h3>Similar</h3>
|
||||||
|
|||||||
Reference in New Issue
Block a user