rescue and fail gracefully when updated user can't be saved

saving the user can fail when the new ign or name are already assigned to a different user.
it's not worth implementing automatic correction because there can be multiple or even circular
'dependencies' of unique names that need to be changed
This commit is contained in:
jomo
2016-12-14 23:57:08 +01:00
parent 381e6e8b5b
commit abeb405bab

View File

@@ -29,8 +29,11 @@ class SessionsController < ApplicationController
if new_ign.present? && new_ign != user.ign
user.name = new_ign if user.ign == user.name
user.ign = new_ign
user.save
flash[:notice] += " Your name has been changed to #{new_ign}!"
if (user.save rescue false)
flash[:notice] += " Your name has been changed to #{new_ign}!"
else
flash[:alert] = "Failed to save your new username #{new_ign}! Please contact admins."
end
end
flash[:alert] = "Remember to validate your email! Your account may be deleted soon!" if !user.confirmed?