Module: Ramaze::Helper::Gravatar

Defined in:
lib/ramaze/helper/gravatar.rb

Instance Method Summary collapse

Instance Method Details

#gravatar(email, size = 32, fallback_path = "/images/gravatar_default.jpg") ⇒ Object

fetches a gravatar from http//www.gravatar.com based on ‘email’ and ‘size’. Falls back to ‘fallback_path’ if no gravatar is found. default ‘fallback_path’ is “/images/gravatar_default.jpg”. example:

class GravatarController < Ramaze::Controller

helper :gravatar

def index
  @gravatar_thumbnail_src = gravatar(session[:email] || '[email protected]')
end

end

/view/gravatar/index.html:
<img src="#{@gravatar_thumbnail_src}" />


21
22
23
24
25
26
27
28
29
# File 'lib/ramaze/helper/gravatar.rb', line 21

def gravatar(email, size = 32, fallback_path = "/images/gravatar_default.jpg")
  emailhash = Digest::MD5.hexdigest(email)

  fallback = Request.current.domain
  fallback.path = fallback_path
  default = Rack::Utils.escape(fallback.to_s)

  return "http://www.gravatar.com/avatar.php?gravatar_id=#{emailhash}&default=#{default}&size=#{size}"
end