summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlfredo Sumaran <alfredo@gitlab.com>2016-03-17 09:41:38 -0500
committerAlfredo Sumaran <alfredo@gitlab.com>2016-03-17 09:41:38 -0500
commit768008f605e59601585cc32c8f6efbfedb659c30 (patch)
tree591f123a4199b95172a40fd5b5dcc6d032ce4831
parent78530162261accaa01be0dc90bf8cd06acb210a6 (diff)
downloadgitlab-ce-768008f605e59601585cc32c8f6efbfedb659c30.tar.gz
Respond to json requests
-rw-r--r--app/controllers/profiles_controller.rb17
1 files changed, 9 insertions, 8 deletions
diff --git a/app/controllers/profiles_controller.rb b/app/controllers/profiles_controller.rb
index 32fca6b838e..30e2886caca 100644
--- a/app/controllers/profiles_controller.rb
+++ b/app/controllers/profiles_controller.rb
@@ -11,15 +11,16 @@ class ProfilesController < Profiles::ApplicationController
def update
user_params.except!(:email) if @user.ldap_user?
- if @user.update_attributes(user_params)
- flash[:notice] = "Profile was successfully updated"
- else
- messages = @user.errors.full_messages.uniq.join('. ')
- flash[:alert] = "Failed to update profile. #{messages}"
- end
-
respond_to do |format|
- format.html { redirect_back_or_default(default: { action: 'show' }) }
+ if @user.update_attributes(user_params)
+ message = "Profile was successfully updated"
+ format.html { redirect_back_or_default(default: { action: 'show' }, options: { notice: message }) }
+ format.json { render json: { message: message } }
+ else
+ message = @user.errors.full_messages.uniq.join('. ')
+ format.html { redirect_back_or_default(default: { action: 'show' }, options: { alert: "Failed to update profile. #{message}" }) }
+ format.json { render json: { message: message }, status: :unprocessable_entity }
+ end
end
end