Skip to content

Commit

Permalink
Add gravatar
Browse files Browse the repository at this point in the history
  • Loading branch information
miharekar committed Dec 30, 2020
1 parent 93b3521 commit 6a54feb
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 2 deletions.
5 changes: 5 additions & 0 deletions app/models/user.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,11 @@ class User < ApplicationRecord
has_many :shots, dependent: :nullify

validates :name, presence: true, if: :public?

def gravatar_url
hash = Digest::MD5.hexdigest(email.to_s.downcase)
"https://www.gravatar.com/avatar/#{hash}.jpg"
end
end

# == Schema Information
Expand Down
6 changes: 5 additions & 1 deletion app/views/people/index.html.slim
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@ h2.blue.center Decent People
tbody
- @users.each do |user|
tr
td = user.name
td
img.vertical-middle src="#{user.gravatar_url}?s=25&d=blank"
span.vertical-middle
'
= user.name
td.nowrap
= link_to "See Their Shots", users_shots_path(user.id), class: "pure-button button-small pure-button-primary"
4 changes: 3 additions & 1 deletion app/views/people/show.html.slim
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
h2.blue.center #{@user.name}'s Shots
h2.blue.center
img.vertical-middle src="#{@user.gravatar_url}?s=50&d=blank"
span.vertical-middle #{@user.name}'s Shots
= render "shots/list", shots: @shots

0 comments on commit 6a54feb

Please sign in to comment.