Skip to content

Commit 4a7d39a

Browse files
author
Christian Kruse
committed
first implementation of avatars
1 parent 33e8b3b commit 4a7d39a

14 files changed

+51
-4
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -24,3 +24,4 @@ coverage
2424

2525
TAGS
2626

27+
/public/system/

Gemfile

+2
Original file line numberDiff line numberDiff line change
@@ -40,4 +40,6 @@ gem 'font-awesome-sass'
4040

4141
gem 'email_validator'
4242

43+
gem "paperclip"
44+
4345
# eof

Gemfile.lock

+10
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,10 @@ GEM
3434
bcrypt-ruby (3.1.5)
3535
bcrypt (>= 3.1.3)
3636
builder (3.2.2)
37+
climate_control (0.0.3)
38+
activesupport (>= 3.0)
39+
cocaine (0.5.5)
40+
climate_control (>= 0.0.3, < 1.0)
3741
coderay (1.1.0)
3842
coffee-rails (4.1.0)
3943
coffee-script (>= 2.2.0)
@@ -83,6 +87,11 @@ GEM
8387
minitest (5.5.0)
8488
multi_json (1.10.1)
8589
orm_adapter (0.5.0)
90+
paperclip (4.2.1)
91+
activemodel (>= 3.0.0)
92+
activesupport (>= 3.0.0)
93+
cocaine (~> 0.5.3)
94+
mime-types
8695
pg (0.17.1)
8796
quiet_assets (1.0.3)
8897
railties (>= 3.1, < 5.0)
@@ -165,6 +174,7 @@ DEPENDENCIES
165174
jquery-rails
166175
kaminari
167176
kramdown
177+
paperclip
168178
pg
169179
quiet_assets
170180
rails (~> 4.1.0)

app/assets/stylesheets/threads.css.scss

+4
Original file line numberDiff line numberDiff line change
@@ -138,4 +138,8 @@
138138
font-size:70%;
139139
}
140140

141+
.registered-user img {
142+
max-height:1em;
143+
}
144+
141145
/* eof */

app/controllers/users_controller.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ def edit
127127

128128
def user_params
129129
params.require(:cf_user).permit(:username, :email, :password,
130-
:password_confirmation)
130+
:password_confirmation, :avatar)
131131
end
132132

133133
def update

app/helpers/message_helper.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ def message_header(thread, message, opts = {})
136136
if not message.message_id == thread.message.message_id and message.user_id == thread.message.user_id
137137
html << " original-poster"
138138
end
139-
html << "\">" + link_to('<em>'.html_safe + t('global.user_profile') + '</em>'.html_safe, user_path(message.owner), class: 'icon-registered-user', title: t('messages.user_link', user: message.owner.username)) + " "
139+
html << "\">" + link_to(image_tag(message.owner.avatar(:thumb)), user_path(message.owner), title: t('messages.user_link', user: message.owner.username)) + " "
140140
else
141141
if not message.message_id == thread.message.message_id and not message.uuid.blank? and message.uuid == thread.message.uuid
142142
html << '<span class="icon-message original-poster" title="' + t('messages.original_poster') + '"><em>' + t("messages.original_poster") + '</em></span>'

app/models/cf_user.rb

+3
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@ class CfUser < ActiveRecord::Base
77
devise :database_authenticatable, :registerable, :recoverable,
88
:rememberable, :confirmable, :trackable
99

10+
has_attached_file :avatar, styles: { medium: "80x80>", thumb: "20x20>" }, default_url: "/images/:style/missing.png"
11+
validates_attachment_content_type :avatar, :content_type => /\Aimage\/.*\Z/
12+
1013
self.primary_key = 'user_id'
1114
self.table_name = 'users'
1215

app/views/users/_user_information.html.erb

+5
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,11 @@
2323
<div class="cntrls"><%= f.email_field :email %></div>
2424
</div>
2525

26+
<div class="cf-cgroup">
27+
<%= f.label :avatar %>
28+
<div class="cntrls"><%= f.file_field :avatar %></div>
29+
</div>
30+
2631
<div class="cf-cgroup">
2732
<%= f.label :password %>
2833
<div class="cntrls"><%= f.password_field :password, autocomplete: 'off' %></div>

app/views/users/edit.html.erb

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
<%
22
content_for :title, t('users.user', name: @user.username)
3-
content_for :h1, "<h1>".html_safe + t('users.user', name: @user.username) + "</h1>".html_safe
3+
content_for :h1, "<h1>".html_safe +
4+
([email protected]? ? image_tag(@user.avatar.url(:medium)) : "") +
5+
t('users.user', name: @user.username) + "</h1>".html_safe
46
%>
57

68
<%= form_for @user, url: user_path(@user), html: {:class => 'form-horizontal'} do |f| %>

app/views/users/show.html.erb

+1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ content_for :h1, "<h1>".html_safe + t('users.user', name: @user.username) + "</h
66

77
<table class="user-info-table">
88
<tr>
9+
<td rowspan="<% if current_user == @user %>5<% else %>4<% end %>"><%= image_tag @user.avatar.url(:medium) %></td>
910
<th><%= t('users.name') %>:</th>
1011
<td><%= @settings.conf('name', @user.username) %></td>
1112
</tr>
+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# -*- coding: utf-8 -*-
2+
3+
class AddAvatarToUsers < ActiveRecord::Migration
4+
def up
5+
add_attachment :users, :avatar
6+
end
7+
8+
def down
9+
remove_attachment :users, :avatar
10+
end
11+
end
12+
13+
# eof

db/structure.sql

+7-1
Original file line numberDiff line numberDiff line change
@@ -1320,7 +1320,11 @@ CREATE TABLE users (
13201320
current_sign_in_at timestamp without time zone,
13211321
last_sign_in_ip character varying,
13221322
current_sign_in_ip character varying,
1323-
sign_in_count integer
1323+
sign_in_count integer,
1324+
avatar_file_name character varying(255),
1325+
avatar_content_type character varying(255),
1326+
avatar_file_size integer,
1327+
avatar_updated_at timestamp without time zone
13241328
);
13251329

13261330

@@ -2611,6 +2615,8 @@ INSERT INTO schema_migrations (version) VALUES ('53');
26112615

26122616
INSERT INTO schema_migrations (version) VALUES ('54');
26132617

2618+
INSERT INTO schema_migrations (version) VALUES ('55');
2619+
26142620
INSERT INTO schema_migrations (version) VALUES ('6');
26152621

26162622
INSERT INTO schema_migrations (version) VALUES ('7');

public/images/medium/missing.png

590 Bytes
Loading

public/images/thumb/missing.png

320 Bytes
Loading

0 commit comments

Comments
 (0)