module ApplicationHelper
  def profile_link(user)
    link_to "@#{user}", profile_path(user)
  end

  def twitter_profile(user)
    "<a href='https://www.twitter.com/#{user}' class='twitter-link' target='_new'>@#{user}</a>".html_safe
  end

  def twitter_avatar(user)
    "<img src='https://avatars.io/twitter/#{user}/small' class='user'>".html_safe
  end

  def current_url
    url_for :only_path => false
  end

  def challenge_id(challenge)
    content_for(:challenge_id, challenge.id) || "Your storage is empty"
  end
end

module ApplicationHelper
  def profile_link(user)
    link_to "@#{user}", profile_path(user)
  end

  def twitter_profile(user)
    "<a href='https://www.twitter.com/#{user}' class='twitter-link' target='_new'>@#{user}</a>".html_safe
  end

  def twitter_avatar(user)
    "<img src='http://identicon-1132.appspot.com/#{Digest::MD5.hexdigest(user)}' class='user'>".html_safe
  end

  def current_url
    url_for :only_path => false
  end

  def challenge_id(challenge)
    content_for(:challenge_id, challenge.id) || "Your storage is empty"
  end
end

Switch Avatar to use an Identicon while Twitter profile pics are unavailable.
Switch Avatar to use an Identicon while Twitter profile pics are unavailable.

I found this service which provides a consistent identicon based on the
passed information. Pass it an MD5 digest of the username as the unique
information.

The Identicons are not as good as an actual profile picture... But
they're definitely better than serving a broken image (or removing the
avatars altogether.)
