aboutsummaryrefslogtreecommitdiffstats
path: root/app
diff options
context:
space:
mode:
Diffstat (limited to 'app')
-rw-r--r--app/models/profile_photo.rb4
-rw-r--r--app/models/user.rb11
-rw-r--r--app/views/user/show.rhtml10
3 files changed, 12 insertions, 13 deletions
diff --git a/app/models/profile_photo.rb b/app/models/profile_photo.rb
index 0811978fe..4ac684f5e 100644
--- a/app/models/profile_photo.rb
+++ b/app/models/profile_photo.rb
@@ -23,7 +23,9 @@ class ProfilePhoto < ActiveRecord::Base
WIDTH = 96
HEIGHT = 96
- # has_one :user
+ belongs_to :user
+
+ attr_accessor :draft
# deliberately don't strip_attributes, so keeps raw photo properly
diff --git a/app/models/user.rb b/app/models/user.rb
index 00fd332ad..7af3ad2d3 100644
--- a/app/models/user.rb
+++ b/app/models/user.rb
@@ -277,19 +277,12 @@ class User < ActiveRecord::Base
# A photograph of the user (to make it all more human)
def set_profile_photo(new_profile_photo)
- old_profile_photo = nil
ActiveRecord::Base.transaction do
if !self.profile_photo.nil?
- old_profile_photo = self.profile_photo
- self.profile_photo = nil
+ self.profile_photo.destroy
end
self.profile_photo = new_profile_photo
- end
- if !old_profile_photo.nil?
- # This doesn't work in the transaction, as destroy starts
- # a new transaction immediately (the database foreign key
- # constraint detects it). Yuck.
- old_profile_photo.destroy
+ self.save
end
end
diff --git a/app/views/user/show.rhtml b/app/views/user/show.rhtml
index a7e19e138..1aeb58391 100644
--- a/app/views/user/show.rhtml
+++ b/app/views/user/show.rhtml
@@ -39,7 +39,7 @@
<div class="single_user">
<p id="user_photo_on_profile">
- <% if @display_user.profile_photo_id %>
+ <% if @display_user.profile_photo %>
<img src="<%= get_profile_photo_url(:url_name => @display_user.url_name) %>">
<% else %>
<% if @is_you %>
@@ -63,8 +63,12 @@
<%= link_to "Send message to " + h(@display_user.name), contact_user_url(:id => @display_user.id) %>
<% if @is_you %>
(just to see how it works)
- <p id="user_change_password_email"><%= link_to "Change your password", signchangepassword_url() %> |
- <%= link_to "Change your email", signchangeemail_url() %>
+ <p id="user_change_password_email">
+ <% if @display_user.profile_photo %>
+ <%= link_to "Change profile photo", set_profile_photo_url() %> |
+ <% end %>
+ <%= link_to "Change your password", signchangepassword_url() %> |
+ <%= link_to "Change your email", signchangeemail_url() %>
</p>
<% end %>
</p>