Raise an error if update fails.

This commit is contained in:
Guo Xiang Tan 2018-08-23 15:36:34 +08:00
parent dd810b8b05
commit 72ed6ae951
1 changed files with 4 additions and 4 deletions

View File

@ -103,17 +103,17 @@ class UserAvatar < ActiveRecord::Base
upload = UploadCreator.new(tempfile, "external-avatar." + ext, origin: avatar_url, type: "avatar").create_for(user.id)
user.create_user_avatar unless user.user_avatar
user.create_user_avatar! unless user.user_avatar
if !user.user_avatar.contains_upload?(upload.id)
user.user_avatar.update_columns(custom_upload_id: upload.id)
user.user_avatar.update!(custom_upload_id: upload.id)
override_gravatar = !options || options[:override_gravatar]
if user.uploaded_avatar_id.nil? ||
!user.user_avatar.contains_upload?(user.uploaded_avatar_id) ||
override_gravatar
user.update_columns(uploaded_avatar_id: upload.id)
user.update!(uploaded_avatar_id: upload.id)
end
end