Skip to content

Commit

Permalink
Users have avatars (paperclip)
Browse files Browse the repository at this point in the history
  • Loading branch information
nono committed Jun 3, 2009
1 parent 897ba0b commit 013010f
Show file tree
Hide file tree
Showing 23 changed files with 64 additions and 33 deletions.
1 change: 1 addition & 0 deletions .gitignore
Expand Up @@ -4,3 +4,4 @@ db/*.sqlite3
log/*.log
tmp/**/*
git_store
public/uploads/**/*
26 changes: 18 additions & 8 deletions app/models/user.rb
@@ -1,15 +1,18 @@
# == Schema Information
# Schema version: 20090505233940
#
# Table name: users
#
# id :integer(4) not null, primary key
# name :string(100)
# homesite :string(255)
# jabber_id :string(255)
# role :string(255) default("moule"), not null
# created_at :datetime
# updated_at :datetime
# id :integer(4) not null, primary key
# name :string(100)
# homesite :string(255)
# jabber_id :string(255)
# role :string(255) default("moule"), not null
# avatar_file_name :string(255)
# avatar_content_type :string(255)
# avatar_file_size :integer(4)
# avatar_updated_at :datetime
# created_at :datetime
# updated_at :datetime
#


Expand Down Expand Up @@ -41,6 +44,13 @@ class User < ActiveRecord::Base

has_friendly_id :name, :use_slug => true

### Avatar ###

has_attached_file :avatar, :styles => { :thumbnail => "100x100>" },
:path => ':rails_root/public/uploads/:id_partition/avatar_:style.:extension',
:url => '/uploads/:id_partition/avatar_:style.:extension',
:default_url => '/images/default_avatar.png'

### Role ###

named_scope :amr, :conditions => {:role => %w[admin moderator reviewer]}
Expand Down
5 changes: 4 additions & 1 deletion app/views/accounts/edit.html.haml
Expand Up @@ -6,7 +6,7 @@
Si vous souhaitez fermer votre compte, veuillez suivre
= link_to("ce lien", close_account_url), '.'

- form_for @account, :url => account_path do |form|
- form_for @account, :url => account_path, :html => { :multipart => true } do |form|
= form.error_messages
%p
Login
Expand All @@ -30,5 +30,8 @@
%p
= uform.label :jabber_id, "Jabber ID"
= 'xmpp:', uform.text_field(:jabber_id)
%p
= uform.label :avatar, "Avatar"
= uform.file_field :avatar
%p
= form.submit "Enregistrer"
2 changes: 1 addition & 1 deletion app/views/admin/sections/index.html.haml
Expand Up @@ -8,7 +8,7 @@
%table
%tr
%th Nom
%th &Eacute;tat
%th État
%th Actions
- @sections.each do |section|
%tr
Expand Down
3 changes: 2 additions & 1 deletion app/views/comments/_comment.html.haml
Expand Up @@ -2,8 +2,9 @@
= link_to "Commentaire : #{h comment.title}", [comment.node, comment]
%p
= posted_by(comment)
== &Eacute;valué à #{comment.score}
== Évalué à #{comment.score}
.content
= image_tag comment.user.avatar.url(:thumbnail), :class => 'avatar'
= sanitize comment.body
%p
= '[', link_to("Répondre", answer_comment_path(:node_id => comment.node_id, :parent_id => comment.id)), ']'
Expand Down
3 changes: 2 additions & 1 deletion app/views/comments/_preview.html.haml
Expand Up @@ -4,6 +4,7 @@
= "Commentaire : #{h preview.title}"
%p
= posted_by(preview)
== &Eacute;valué à #{preview.score}
== Évalué à #{preview.score}
.content
= image_tag current_user.avatar.url(:thumbnail), :class => 'avatar'
= sanitize preview.body
2 changes: 1 addition & 1 deletion app/views/comments/edit.html.haml
@@ -1,4 +1,4 @@
=h2 "&Eacute;diter un commentaire"
=h2 "Éditer un commentaire"

= render "preview", :object => @comment if @preview_mode

Expand Down
2 changes: 1 addition & 1 deletion app/views/comments/new.html.haml
@@ -1,4 +1,4 @@
=h2 "&Eacute;crire un commentaire"
=h2 "Écrire un commentaire"

= render "preview", :object => @comment if @preview_mode

Expand Down
1 change: 1 addition & 0 deletions app/views/diaries/_diary.html.haml
Expand Up @@ -2,6 +2,7 @@
%h3
= link_to "Journal : #{h diary.title}", [diary.owner, diary]
%p
= image_tag diary.owner.avatar.url(:thumbnail), :class => 'avatar'
= posted_by(diary)
.content
= sanitize diary.body
Expand Down
1 change: 1 addition & 0 deletions app/views/diaries/_preview.html.haml
Expand Up @@ -2,6 +2,7 @@
%h3
= "Journal : #{h preview.title}"
%p
= image_tag current_user.avatar.url(:thumbnail), :class => 'avatar'
= posted_by(preview)
.content
= sanitize preview.body
Expand Down
4 changes: 2 additions & 2 deletions app/views/moderation/interviews/_edition.html.haml
@@ -1,7 +1,7 @@
%article
%h2 &Eacute;ditions
%h2 Éditions
%p
= link_to "&Eacute;diter", edit_moderation_interview_path(:id => @interview.id)
= link_to "Éditer", edit_moderation_interview_path(:id => @interview.id)
%h2 Modération
- form_tag accept_moderation_interview_path(@interview) do
= submit_tag "Publier"
Expand Down
2 changes: 1 addition & 1 deletion app/views/moderation/interviews/edit.html.haml
@@ -1,4 +1,4 @@
=h2 "&Eacute;diter une proposition d'entretien"
=h2 "Éditer une proposition d'entretien"

- form_for [:moderation, @interview] do |form|
= render form
4 changes: 2 additions & 2 deletions app/views/moderation/news/_edition.html.haml
@@ -1,7 +1,7 @@
%article
%h2 &Eacute;ditions
%h2 Éditions
%p
= link_to "&Eacute;diter", edit_moderation_news_path(@news)
= link_to "Éditer", edit_moderation_news_path(@news)
%p
Liste des dernières modifications :
%ul
Expand Down
2 changes: 1 addition & 1 deletion app/views/moderation/news/edit.html.haml
@@ -1,4 +1,4 @@
=h2 "&Eacute;diter une dépêche"
=h2 "Éditer une dépêche"

- form_for [:moderation, setup_news(@news)] do |form|
= render form
Expand Down
4 changes: 2 additions & 2 deletions app/views/moderation/polls/_edition.html.haml
@@ -1,7 +1,7 @@
%article
%h2 &Eacute;ditions
%h2 Éditions
%p
= link_to "&Eacute;diter", edit_moderation_poll_path(:id => @poll.id)
= link_to "Éditer", edit_moderation_poll_path(:id => @poll.id)
%h2 Modération
- form_tag accept_moderation_poll_path(@poll) do
= submit_tag "Publier"
Expand Down
2 changes: 1 addition & 1 deletion app/views/moderation/polls/edit.html.haml
@@ -1,4 +1,4 @@
=h2 "&Eacute;diter un sondage"
=h2 "Éditer un sondage"

- form_for [:moderation, setup_poll(@poll)] do |form|
= render form
2 changes: 1 addition & 1 deletion app/views/posts/edit.html.haml
@@ -1,4 +1,4 @@
=h2 "&Eacute;diter un message"
=h2 "Éditer un message"

= render "preview", :object => @post if @preview_mode

Expand Down
4 changes: 2 additions & 2 deletions app/views/wiki_pages/_edition.html.haml
@@ -1,8 +1,8 @@
%article
%h2
&Eacute;ditions
Éditions
%p
= link_to "&Eacute;diter", edit_wiki_page_path(edition)
= link_to "Éditer", edit_wiki_page_path(edition)
%p
Liste des dernières modifications :
%ul
Expand Down
1 change: 1 addition & 0 deletions config/environment.rb
Expand Up @@ -22,6 +22,7 @@
config.gem 'mysql', :version => '~>2.7'
config.gem 'haml', :version => '~>2.0'
config.gem 'friendly_id', :version => '~>2.0'
config.gem 'paperclip', :version => '~>2.1'
config.gem 'wikitext', :version => '~>1.5'
config;gem 'authlogic', :version => '~>2.0'
config.gem 'rubyist-aasm', :lib => 'aasm', :version => '~>2.0'
Expand Down
7 changes: 7 additions & 0 deletions db/migrate/20090105233501_create_users.rb
Expand Up @@ -5,6 +5,13 @@ def self.up
t.string :homesite
t.string :jabber_id
t.string :role, :null => false, :default => 'moule'

# Avatar
t.string :avatar_file_name
t.string :avatar_content_type
t.integer :avatar_file_size
t.datetime :avatar_updated_at

t.timestamps
end
end
Expand Down
Binary file added public/images/default_avatar.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions public/stylesheets/style.css
Expand Up @@ -32,4 +32,5 @@ aside .login p { font-weight: bold; }
.comment { border:1px solid black; }
#tracker .fix a, #tracker .invalid a { text-decoration: line-through; }
.tracker.fix a, .tracker.invalid a { text-decoration: line-through; }
.avatar { float:left; margin: 5px 10px; }

18 changes: 11 additions & 7 deletions test/unit/user_test.rb
Expand Up @@ -2,13 +2,17 @@
#
# Table name: users
#
# id :integer(4) not null, primary key
# name :string(100)
# homesite :string(255)
# jabber_id :string(255)
# role :string(255) default("moule"), not null
# created_at :datetime
# updated_at :datetime
# id :integer(4) not null, primary key
# name :string(100)
# homesite :string(255)
# jabber_id :string(255)
# role :string(255) default("moule"), not null
# avatar_file_name :string(255)
# avatar_content_type :string(255)
# avatar_file_size :integer(4)
# avatar_updated_at :datetime
# created_at :datetime
# updated_at :datetime
#

require File.dirname(__FILE__) + '/../test_helper'
Expand Down

0 comments on commit 013010f

Please sign in to comment.