I have gone through this railscast on Gravatars and i now have the below helper method in my application helper.
module ApplicationHelper
def avatar_url(user)
gravatar_id = Digest::MD5.hexdigest(user.email.downcase)
"http://gravatar.com/avatar/#{gravatar_id}.png?s=200"
end
end
and i have this in my view
<%= image_tag avatar_url(user) %>
how can i modify the helper so it will accept a size option that changes the s=200 to the size specified?
Thanks
module ApplicationHelper
def avatar_url(user, size)
gravatar_id = Digest::MD5.hexdigest(user.email.downcase)
"http://gravatar.com/avatar/#{gravatar_id}.png?s=#{size}"
end
end
Then call:
<%= image_tag avatar_url(user, 200) %>
You can also check Michael Hartl's guide.
In the application_helper.rb
file under the app/helpers
folder, add the following method:
# app/helpers/application_helper.rb
def gravatar_for(user, options = { size: 200})
gravatar_id = Digest::MD5::hexdigest(user.email.downcase)
size = options[:size]
gravatar_url = "https://secure.gravatar.com/avatar/#{gravatar_id}?s=#{size}"
image_tag(gravatar_url, alt: user.username, class: "img-circle")
end
Then call it at the show.html.erb
:
<%= gravatar_for @user, size: 200%>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With