From c5a3bfdfa90f219c19814adbde70372caf958283 Mon Sep 17 00:00:00 2001 From: Sam Date: Thu, 29 May 2014 14:38:52 +1000 Subject: [PATCH] BUGFIX: missing avatars in search --- lib/search/search_result.rb | 24 +++++++++++++++++------- 1 file changed, 17 insertions(+), 7 deletions(-) diff --git a/lib/search/search_result.rb b/lib/search/search_result.rb index 01e3dbf2527..d14b15c0bfb 100644 --- a/lib/search/search_result.rb +++ b/lib/search/search_result.rb @@ -11,7 +11,7 @@ class Search attr_accessor :color, :text_color # User attributes - attr_accessor :avatar_template + attr_accessor :avatar_template, :uploaded_avatar_id def initialize(row) row.symbolize_keys! @@ -21,10 +21,15 @@ class Search def as_json(options = nil) json = {id: @id, title: @title, url: @url} - json[:avatar_template] = @avatar_template if @avatar_template.present? - json[:color] = @color if @color.present? - json[:text_color] = @text_color if @text_color.present? - json[:blurb] = @blurb if @blurb.present? + [ :avatar_template, + :uploaded_avatar_id, + :color, + :text_color, + :blurb + ].each do |k| + val = send(k) + json[k] = val if val + end json end @@ -36,8 +41,13 @@ class Search end def self.from_user(u) - SearchResult.new(type: :user, id: u.username_lower, title: u.username, url: "/users/#{u.username_lower}").tap do |r| - r.avatar_template = u.avatar_template + SearchResult.new( + type: :user, + id: u.username_lower, + title: u.username, + url: "/users/#{u.username_lower}").tap do |r| + r.uploaded_avatar_id = u.uploaded_avatar_id + r.avatar_template = u.avatar_template end end