diff options
Diffstat (limited to 'app/controllers/profiles/preferences_controller.rb')
-rw-r--r-- | app/controllers/profiles/preferences_controller.rb | 25 |
1 files changed, 10 insertions, 15 deletions
diff --git a/app/controllers/profiles/preferences_controller.rb b/app/controllers/profiles/preferences_controller.rb index 4d88491e9a8..add5046e213 100644 --- a/app/controllers/profiles/preferences_controller.rb +++ b/app/controllers/profiles/preferences_controller.rb @@ -9,23 +9,18 @@ class Profiles::PreferencesController < Profiles::ApplicationController end def update - begin - result = Users::UpdateService.new(current_user, preferences_params.merge(user: user)).execute - - if result[:status] == :success - flash[:notice] = _('Preferences saved.') - else - flash[:alert] = _('Failed to save preferences.') - end - rescue ArgumentError => e - # Raised when `dashboard` is given an invalid value. - flash[:alert] = _("Failed to save preferences (%{error_message}).") % { error_message: e.message } - end + result = Users::UpdateService.new(current_user, preferences_params.merge(user: user)).execute + if result[:status] == :success + message = _('Preferences saved.') - respond_to do |format| - format.html { redirect_to profile_preferences_path } - format.js + render json: { type: :notice, message: message } + else + render status: :bad_request, json: { type: :alert, message: _('Failed to save preferences.') } end + rescue ArgumentError => e + # Raised when `dashboard` is given an invalid value. + message = _("Failed to save preferences (%{error_message}).") % { error_message: e.message } + render status: :bad_request, json: { type: :alert, message: message } end private |