Module: BarkestCore::UsersHelper
- Defined in:
- app/helpers/barkest_core/users_helper.rb
Overview
This module adds helper methods related to users in general (not just the current user).
Based on the tutorial from [www.railstutorial.org](www.railstutorial.org).
Instance Method Summary collapse
-
#gravatar_for(user, options = {}) ⇒ Object
Returns the Gravatar for the given user.
Instance Method Details
#gravatar_for(user, options = {}) ⇒ Object
Returns the Gravatar for the given user.
Based on the tutorial from [www.railstutorial.org](www.railstutorial.org).
The user
is the user you want to get the gravatar for.
Valid options:
-
size
The size (in pixels) for the returned gravatar. The gravatar will be a square image using this value as both the width and height. The default is 80 pixels. -
default
The default image to return when no image is set. This can be nil, :mm, :identicon, :monsterid, :wavatar, or :retro. The default is :identicon.
21 22 23 24 25 26 27 28 29 |
# File 'app/helpers/barkest_core/users_helper.rb', line 21 def gravatar_for(user, = {}) = { size: 80, default: :identicon }.merge( || {}) [:default] = [:default].to_s.to_sym unless [:default].nil? || [:default].is_a?(Symbol) gravatar_id = Digest::MD5::hexdigest(user.email.downcase) size = [:size] default = [:mm, :identicon, :monsterid, :wavatar, :retro].include?([:default]) ? "&d=#{[:default]}" : '' gravatar_url = "https://secure.gravatar.com/avatar/#{gravatar_id}?s=#{size}#{default}" image_tag(gravatar_url, alt: user.name, class: 'gravatar', style: "width: #{size}px, height: #{size}px") end |