Skip to content
This repository
Browse code

Revert Avatar upload feature.

  • Loading branch information...
commit bc04da00a6999a4322d7166829095e8e0783e108 1 parent bea7d21
Jason Lee authored
14 app/helpers/users_helper.rb
@@ -27,7 +27,7 @@ def user_avatar_width_for_size(size)
27 27 else size
28 28 end
29 29 end
30   -
  30 +
31 31 def user_avatar_tag(user, size = :normal, opts = {})
32 32 link = opts[:link] || true
33 33
@@ -38,10 +38,14 @@ def user_avatar_tag(user, size = :normal, opts = {})
38 38 return image_tag("http://gravatar.com/avatar/#{hash}.png?s=#{width}")
39 39 end
40 40
41   - hash = Digest::MD5.hexdigest(user.email || "")
42   - img_src = "http://gravatar.com/avatar/#{hash}.png?s=#{width}"
43   - img = image_tag(img_src, :style => "width:#{width}px;height:#{width}px;")
44   -
  41 + if user.avatar.blank?
  42 + hash = Digest::MD5.hexdigest(user.email || "")
  43 + img_src = "http://gravatar.com/avatar/#{hash}.png?s=#{width}"
  44 + img = image_tag(img_src, :style => "width:#{width}px;height:#{width}px;")
  45 + else
  46 + img = image_tag(user.avatar.url(size), :style => "width:#{width}px;height:#{width}px;")
  47 + end
  48 +
45 49 if link
46 50 raw %(<a href="#{user_path(user.login)}" #{user_popover_info(user)} class="user_avatar">#{img}</a>)
47 51 else
4 app/models/user.rb
@@ -28,6 +28,8 @@ class User
28 28 field :replies_count, :type => Integer, :default => 0
29 29 field :likes_count, :type => Integer, :default => 0
30 30
  31 + mount_uploader :avatar, AvatarUploader
  32 +
31 33 index :login
32 34 index :email
33 35 index :location
@@ -53,7 +55,7 @@ def read_notifications(notifications)
53 55 end
54 56
55 57 attr_accessor :password_confirmation
56   - attr_accessible :name, :email, :location, :bio, :website, :github, :tagline
  58 + attr_accessible :name, :email, :location, :bio, :website, :github, :tagline, :avatar
57 59
58 60 validates :login, :format => {:with => /\A\w+\z/, :message => '只允许数字、大小写字母和下划线'}, :length => {:in => 3..20}, :presence => true, :uniqueness => {:case_sensitive => false}
59 61
18 app/uploaders/avatar_uploader.rb
... ... @@ -0,0 +1,18 @@
  1 +# coding: utf-8
  2 +class AvatarUploader < BaseUploader
  3 + version :normal do
  4 + process :resize_to_fill => [48, 48]
  5 + end
  6 +
  7 + version :small do
  8 + process :resize_to_fill => [16, 16]
  9 + end
  10 +
  11 + version :large do
  12 + process :resize_to_fill => [64, 64]
  13 + end
  14 +
  15 + version :big do
  16 + process :resize_to_fill => [120, 120]
  17 + end
  18 +end
6 app/views/account/edit.html.erb
@@ -13,6 +13,12 @@
13 13 </div>
14 14 </div>
15 15 <div class="clearfix">
  16 + <%= f.label :avatar %>
  17 + <div class="input">
  18 + <%= f.file_field :avatar %>
  19 + </div>
  20 + </div>
  21 + <div class="clearfix">
16 22 <%= f.label :email %>
17 23 <div class="input">
18 24 <%= f.text_field :email, :class => "span6" %>

0 comments on commit bc04da0

Please sign in to comment.
Something went wrong with that request. Please try again.