diff options
author | Francis Irving <francis@mysociety.org> | 2010-07-14 12:29:05 +0100 |
---|---|---|
committer | Francis Irving <francis@mysociety.org> | 2010-07-14 12:29:05 +0100 |
commit | 2bb33debfb2ada973215f4be7c829ef8a17eb13c (patch) | |
tree | ac0624dfc007c6153eea2ae684fb7fb50f904074 | |
parent | 5972a15c7f781592f8757ba2799c5286d04dc771 (diff) |
Make changing photo work
-rw-r--r-- | app/models/user.rb | 10 |
1 files changed, 8 insertions, 2 deletions
diff --git a/app/models/user.rb b/app/models/user.rb index eb8089cf1..4cd3394b4 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -275,17 +275,23 @@ class User < ActiveRecord::Base return PublicBody.extract_domain_from_email(self.email) end - # XXX profile photos not fully implemented yet + # 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 - old_profile_photo.destroy end new_profile_photo.user = self 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 + end end # Used for default values of last_daily_track_email |