Skip to content

Commit

Permalink
update current_user_serializer and remove default url from avatar
Browse files Browse the repository at this point in the history
  • Loading branch information
colinyoung87 committed Oct 29, 2015
1 parent d21f30c commit 75d3c4a
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
2 changes: 1 addition & 1 deletion app/models/user.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ class User < ActiveRecord::Base

has_and_belongs_to_many :projects, -> { order(name: :asc) }

has_attached_file :avatar, styles: { thumb: "300x300#" }, default_url: nil
has_attached_file :avatar, styles: { thumb: "300x300#" }
validates_attachment_content_type :avatar, content_type: %r{^image\/}

validates :first_name, :last_name, presence: true
Expand Down
15 changes: 14 additions & 1 deletion app/serializers/current_user_serializer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,19 @@ def filter(keys)
end

def avatar_url
object.avatar.url(:thumb)
if object.avatar_file_name.present?
user.avatar.url(:thumb)
else
gravatar_url
end
end

def gravatar_url(size = 200)
base_url = "https://www.gravatar.com/avatar/"
opts = "?d=blank&s="

hash = Digest::MD5.hexdigest(object.email)

base_url + hash + opts + size.to_s
end
end

0 comments on commit 75d3c4a

Please sign in to comment.