Skip to content

Commit

Permalink
Hotfix: Create and upload avatar in DB transaction
Browse files Browse the repository at this point in the history
  • Loading branch information
gregorbg committed Oct 29, 2024
1 parent 404d39b commit 5249ce8
Showing 1 changed file with 11 additions and 9 deletions.
20 changes: 11 additions & 9 deletions app/controllers/users_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -163,15 +163,17 @@ def upload_avatar
thumbnail_json = params.require(:thumbnail)
thumbnail = JSON.parse(thumbnail_json).symbolize_keys

user_avatar = UserAvatar.create!(
user: user_to_edit,
thumbnail_crop_x: thumbnail[:x],
thumbnail_crop_y: thumbnail[:y],
thumbnail_crop_w: thumbnail[:width],
thumbnail_crop_h: thumbnail[:height],
)

user_avatar.attach_image(upload_file)
ActiveRecord::Base.transaction do
user_avatar = UserAvatar.create!(
user: user_to_edit,
thumbnail_crop_x: thumbnail[:x],
thumbnail_crop_y: thumbnail[:y],
thumbnail_crop_w: thumbnail[:width],
thumbnail_crop_h: thumbnail[:height],
)

user_avatar.attach_image(upload_file)
end

render json: { ok: user_avatar.valid? }
end
Expand Down

0 comments on commit 5249ce8

Please sign in to comment.