Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Comparing changes

Choose two branches to see what's changed or to start a new pull request. If you need to, you can also compare across forks.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also compare across forks.
base fork: bob/Messager
base: c69acf9287
...
head fork: bob/Messager
compare: be96d8d920
Checking mergeability… Don't worry, you can still create the pull request.
  • 3 commits
  • 12 files changed
  • 0 commit comments
  • 1 contributor
View
1  .gitignore
@@ -3,3 +3,4 @@ config/database.yml
db/*.sqlite3
log/*.log
tmp/**/*
+public/system/**
View
3  Gemfile
@@ -30,4 +30,5 @@ gem 'mysql2'
# gem 'webrat'
# end
-gem 'devise'
+gem 'devise'
+gem "paperclip", :git => "git://github.com/thoughtbot/paperclip.git"
View
9 Gemfile.lock
@@ -1,3 +1,11 @@
+GIT
+ remote: git://github.com/thoughtbot/paperclip.git
+ revision: 1738ea1dcaf65860c53088cc62ad7f0887e629ca
+ specs:
+ paperclip (2.3.8)
+ activerecord
+ activesupport
+
GEM
remote: http://rubygems.org/
specs:
@@ -77,4 +85,5 @@ PLATFORMS
DEPENDENCIES
devise
mysql2
+ paperclip!
rails (= 3.0.2)
View
30 app/controllers/profile_controller.rb
@@ -1,15 +1,45 @@
class ProfileController < ApplicationController
+ before_filter :authenticate_user!
+
def profile
+
end
def change_fullname
end
+ def change_password
+ @user = current_user
+ end
+
+ def update_password
+ @user = current_user
+ if @user.update_with_password(params[:user])
+ flash[:notice] = "Password changed"
+ redirect_to profile_path
+ else
+ render :change_password
+ end
+ end
def edit
@user = User.find(params[:id])
end
+
+ def avatar
+
+ end
+
+ def update_avatar
+ @user = current_user
+ if @user.update_attributes(params[:user])
+ flash[:notice] = "Avatar changed"
+ redirect_to profile_path
+ else
+ render :avatar
+ end
+ end
def update
View
12 app/models/user.rb
@@ -5,7 +5,17 @@ class User < ActiveRecord::Base
:recoverable, :rememberable, :trackable, :validatable
# Setup accessible (or protected) attributes for your model
- attr_accessible :email, :password, :password_confirmation, :remember_me, :fullname
+ attr_accessible :email, :password, :password_confirmation, :remember_me, :fullname, :avatar
has_many :messages
+
+ has_attached_file :avatar,
+ # :path => ':rails_root/public/assets/avatars/:id/:style/:basename.:extension',
+ # :url => '...',
+ :styles => { :medium => "300x300>", :thumb => "100x100>" },
+ :default_url => "rails.png"
+
+ validates_attachment_content_type :avatar, :content_type => ['image/jpeg', 'image/pjpeg', 'image/png', 'image/gif']
+ validates_attachment_size :avatar, :less_than => 500.kilobytes
+
end
View
10 app/views/profile/avatar.html.erb
@@ -0,0 +1,10 @@
+<%= form_for :user, :url => update_avatar_path, :html => { :multipart => true, :method => :put } do |form| %>
+ <%= form.error_messages %>
+
+ <p>
+ <%= form.label :avatar %><br/>
+ <%= form.file_field :avatar %>
+ </p>
+
+ <%= form.submit "Change avatar" %>
+<% end %>
View
22 app/views/profile/change_password.html.erb
@@ -0,0 +1,22 @@
+<h2>Change your password</h2>
+
+<%= form_for(@user, :url => update_password_path, :html => { :method => :put }) do |f| %>
+ <%= f.error_messages %>
+
+ <p>
+ <%= f.label :current_password %><br/>
+ <%= f.password_field :current_password %>
+ </p>
+
+ <p>
+ <%= f.label :password %><br/>
+ <%= f.password_field :password %>
+ </p>
+
+ <p>
+ <%= f.label :password_confirmation %><br/>
+ <%= f.password_field :password_confirmation %>
+ </p>
+
+ <p><%= f.submit "Change my password" %></p>
+<% end %>
View
11 app/views/profile/profile.html.erb
@@ -1,6 +1,13 @@
<h1>Profile</h1>
+
+<p>Email: <%= current_user.email %></p>
+<p>Full name: <%= current_user.fullname %></p>
+
+<p><%= image_tag current_user.avatar.url(:medium) %></p>
+
<ul>
- <li><%= link_to "Change fullname", change_fullname_path(current_user) %></li>
- <li><%= link_to "Change password", edit_user_password_path %></li>l
+ <li><%= link_to "Change fullname", profile_change_fullname_path %></li>
+ <li><%= link_to "Change password", change_password_path %></li>
+ <li><%= link_to "Change avatar", avatar_path %></li>
<ul>
View
5 app/views/welcome/index.html.erb
@@ -11,7 +11,10 @@
<% @messages.each do |message| %>
<tr>
- <td><%= user_human(message.user) %></td>
+ <td>
+ <%= image_tag message.user.avatar.url(:thumb) %><br/>
+ <%= user_human(message.user) %>
+ </td>
<td style="border-style:solid; border-color:#<%= message.color %>"><%= message.body %></td>
<td><%= image_tag(Message::IMG_DIR + message.emotion) unless message.emotion.blank? %></td>
<td><%= message.created_at.to_s(:my_datetime) %></td>
View
15 config/routes.rb
@@ -1,10 +1,17 @@
Messager::Application.routes.draw do
- get "profile/profile", :as => "profile"
-
- match 'profile/:id/edit', :as => 'profile#edit'
+
+ match "profile" => "profile#profile", :as => "profile"
+ match 'profile/edit' => 'profile#edit', :as => "profile_edit"
+ match 'profile/change_fullname' => 'profile#change_fullname', :as => "profile_change_fullname"
+
+ controller :profile do
+ get "profile/change_password" => :change_password, :as => "change_password"
+ put "profile/update_password" => :update_password, :as => "update_password"
+ get "profile/avatar" => :avatar, :as => "avatar"
+ put "profile/update_avatar" => :update_avatar, :as => "update_avatar"
+ end
get "welcome/index"
-
get "welcome/about", :as => "about"
devise_for :users
View
15 db/migrate/20110323151110_add_avatar_columns_to_user.rb
@@ -0,0 +1,15 @@
+class AddAvatarColumnsToUser < ActiveRecord::Migration
+ def self.up
+ add_column :users, :avatar_file_name, :string
+ add_column :users, :avatar_content_type, :string
+ add_column :users, :avatar_file_size, :integer
+ add_column :users, :avatar_updated_at, :datetime
+ end
+
+ def self.down
+ remove_column :users, :avatar_file_name
+ remove_column :users, :avatar_content_type
+ remove_column :users, :avatar_file_size
+ remove_column :users, :avatar_updated_at
+ end
+end
View
6 db/schema.rb
@@ -10,7 +10,7 @@
#
# It's strongly recommended to check this file into your version control system.
-ActiveRecord::Schema.define(:version => 20110321154400) do
+ActiveRecord::Schema.define(:version => 20110323151110) do
create_table "messages", :force => true do |t|
t.string "body"
@@ -39,6 +39,10 @@
t.datetime "confirmation_sent_at"
t.datetime "created_at"
t.datetime "updated_at"
+ t.string "avatar_file_name"
+ t.string "avatar_content_type"
+ t.integer "avatar_file_size"
+ t.datetime "avatar_updated_at"
end
add_index "users", ["confirmation_token"], :name => "index_users_on_confirmation_token", :unique => true

No commit comments for this range

Something went wrong with that request. Please try again.