diff options
author | Alfredo Sumaran <alfredo@gitlab.com> | 2016-03-17 09:41:38 -0500 |
---|---|---|
committer | Alfredo Sumaran <alfredo@gitlab.com> | 2016-03-17 09:41:38 -0500 |
commit | 768008f605e59601585cc32c8f6efbfedb659c30 (patch) | |
tree | 591f123a4199b95172a40fd5b5dcc6d032ce4831 | |
parent | 78530162261accaa01be0dc90bf8cd06acb210a6 (diff) | |
download | gitlab-ce-768008f605e59601585cc32c8f6efbfedb659c30.tar.gz |
Respond to json requests
-rw-r--r-- | app/controllers/profiles_controller.rb | 17 |
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 |