How can I insert my gravatar image in an email that I want to send out with Ruby on Rails? According to Gravatar I need to insert the following code into my Ruby on Rails app:
image_src = "http://www.gravatar.com/avatar/#{hash}"
Hash is essentially an encoded string for an email address. Hash is equal to:
hash = Digest::MD5.hexdigest(email_address)
I created a method called "gravatarurl", which you can see below:
def gravatarurl
hash = Digest::MD5.hexdigest("myemail@google.com")
puts "http://www.gravatar.com/avatar/#{hash}"
end
Now, the code that I have in the mailer is:
def emailwithphoto
@user1 = User.find(1)
mail(to: "#{@user1.email}",
from: "MNC@mydomain.com",
subject: "Attempting to include image in this email")
end
In file app/views/image_mailer/emailwithphoto.rb I have the code:
<img alt="" src="<%= @user1.gravatarurl %>" class="mcnImage">
If I hard code my gravatar url into the file "emailwithphoto.rb" then I can see my gravatar photo, but I need the email to be dynamic.
What am I missing or not seeing? Thank you in advance for your help!