aboutsummaryrefslogtreecommitdiffstats
path: root/app/models
diff options
context:
space:
mode:
Diffstat (limited to 'app/models')
-rw-r--r--app/models/profile_photo.rb4
-rw-r--r--app/models/user.rb11
2 files changed, 5 insertions, 10 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