Commit 7a4d2132

mo k <mo@mokhan.ca>
2012-08-09 12:56:45
convert all avatar_url to avatar_for
1 parent fc12a08
app/helpers/application_helper.rb
@@ -1,18 +1,14 @@
 module ApplicationHelper
-  def avatar_url(user, options = {size: 260})
+  def avatar_for(user, options = {size:260, class:''})
     if user.avatar == nil 
-      default_url = "#{root_url}assets/chefhat_profile.PNG"
-      gravatar_id = Digest::MD5.hexdigest(user.email.downcase)
-      "http://gravatar.com/avatar/#{gravatar_id}.png?&d=#{CGI.escape(default_url)}&s={options[:size]}"
+      return gravatar_for(user, options)
     else
-      user.avatar.avatar.thumb.url
+      image_tag(user.avatar.avatar.thumb.url, alt: user.name, class: options[:class])
     end
   end
   def gravatar_for(user, options = { size: 50 })
     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.name, class: 'gravatar')
+    image_tag("https://secure.gravatar.com/avatar/#{gravatar_id}?s=#{options[:size]}", alt: user.name, class: 'gravatar')
   end
   def full_title(title)
     if( title.blank? )
app/views/creations/edit.html.erb
@@ -5,7 +5,7 @@
 <div class="row">
   <div class="span3">
     <div class="thumbnail">
-      <img src="<%= avatar_url current_user %>&amp;s=260" alt="<%= current_user.name %>" />
+      <%= avatar_for(current_user) %>
       <div class="caption">
         <h5><%= current_user.name %></h5>
       </div>
app/views/creations/new.html.erb
@@ -5,7 +5,7 @@
 <div class="row">
   <div class="span3">
     <div class="thumbnail">
-      <img src="<%= avatar_url current_user %>&amp;s=260" alt="<%= current_user.name %>" />
+      <%= avatar_for(current_user) %>
       <div class="caption">
         <h5><%= current_user.name %></h5>
       </div>
app/views/favorites/index.html.erb
@@ -12,7 +12,7 @@
         <li class="span3">
         <div class="thumbnail">
           <a href="<%= url_for profile_path(favorite.user) %>" class="thumbnail">
-            <img src="<%= avatar_url favorite.user %>&amp;s=260" alt="<%= favorite.user.name %>" />
+            <%= avatar_for(favorite.user) %>
           </a>
           <div class="caption">
             <h5><%= favorite.user.name %></h5>
app/views/profiles/favorites.html.erb
@@ -2,7 +2,7 @@
 <div class="row">
   <div class="span3">
     <div class="thumbnail">
-      <img src="<%= avatar_url current_user %>&amp;s=260" alt="<%= current_user.name %>" />
+      <%= avatar_for(current_user) %>
       <div class="caption">
         <h5><%= current_user.name %></h5>
       </div>
app/views/profiles/index.html.erb
@@ -22,11 +22,7 @@
           <tr>
             <td>
               <ul class="thumbnails">
-                <li>
-                <a href="<%= url_for profile_path(profile) %>">
-                  <%= image_tag avatar_url(profile), :class => "thumbnail", :alt => profile.name %>
-                </a>
-                </li>
+                <li><a href="<%= url_for profile_path(profile) %>"><%= avatar_for(profile, {class: 'thumbnail'}) %></a></li>
               </ul>
             </td>
             <td><%= link_to profile.name, profile_path(profile) %></td>
app/views/profiles/mine.html.erb
@@ -2,7 +2,7 @@
 <div class="row">
   <div class="span3">
     <div class="thumbnail">
-      <img src="<%= avatar_url current_user %>" alt="<%= current_user.name %>" />
+      <%= avatar_for(current_user) %>
       <div class="caption">
         <h5><%= current_user.name %></h5>
         <p> <%= link_to "My Public Profile", profile_path(current_user) %></p>
app/views/profiles/show.html.erb
@@ -10,7 +10,7 @@
 <div class="row">
   <div class="span3">
     <div class="thumbnail">
-      <img src="<%= avatar_url @profile %>" alt="<%= @profile.name %>" />
+      <%= avatar_for(@profile) %>
       <div class="caption">
         <h5><%= @profile.name %></h5>
         <p>member since: <%= @profile.created_at.to_s :foomat %></p>
app/views/registrations/edit.html.erb
@@ -7,7 +7,7 @@
   <div class="row">
     <div class="span3">
       <div class="thumbnail">
-        <img src="<%= avatar_url current_user %>" alt="<%= current_user.name %>" />
+        <%= avatar_for current_user %>
         <div class="caption">
           <h5><%= current_user.name %></h5>
           <p>member since: <%= current_user.created_at.to_s :foomat %></p>
app/views/search/index.html.erb
@@ -14,7 +14,7 @@
   <% @members.each do |artist| %>
     <div class="span3">
       <div class="thumbnail">
-        <a href="<%= url_for profile_path(artist) %>"><img src="<%= avatar_url artist %>&amp;s=260" alt="<%= artist.name %>" /></a>
+        <a href="<%= url_for profile_path(artist) %>"><%= avatar_for(artist) %></a>
         <div class="caption">
           <h5><%= artist.name %></h5>
         </div>