Module: UsersHelper

Defined in:
app/helpers/users_helper.rb

Instance Method Summary collapse

Instance Method Details

#gravatar_img(user, options = {}) ⇒ Object



7
8
9
# File 'app/helpers/users_helper.rb', line 7

def gravatar_img(user, options = {})
  image_tag gravatar_url(user.email), {:class => 'avatar'}.merge(options)
end

#gravatar_url(email = nil, size = 80) ⇒ Object



11
12
13
14
15
16
17
18
19
# File 'app/helpers/users_helper.rb', line 11

def gravatar_url(email = nil, size = 80)
  default = '/assets/adva_cms/avatar.gif'
  return default if Rails.env.test?
  return default if email.blank?
  require 'digest/md5'
  digest = Digest::MD5.hexdigest(email)
  # TODO #{ActionController::AbstractRequest.relative_url_root} missing in Rails 2.2
  "http://www.gravatar.com/avatar.php?size=#{size}&gravatar_id=#{digest}&default=http://#{request.host_with_port}/assets/adva_cms/avatar.gif"
end


21
22
23
24
25
26
27
# File 'app/helpers/users_helper.rb', line 21

def link_to_author resource, options = {}
  include_email = options[:include_email] && resource.respond_to?(:author_email)
  name = resource.author_name
  text = resource.author_homepage.blank? ? name : link_to(h(name), h(resource.author_homepage))
  text = "#{text} (#{resource.author_email})" if include_email
  text.html_safe
end

#who(name) ⇒ Object



2
3
4
5
# File 'app/helpers/users_helper.rb', line 2

def who(name)
  name = name.name if name.is_a? User
  return current_user.name == name ? "You" : name
end