From 0161694c3b83332a08c16f662445b227455c70e5 Mon Sep 17 00:00:00 2001 From: Alexander Bach Date: Fri, 11 Sep 2015 09:31:22 +0200 Subject: [PATCH] Extract save functionality for new menu saves --- app/controllers/my_controller.rb | 28 ++++++++++++++++------------ 1 file changed, 16 insertions(+), 12 deletions(-) diff --git a/app/controllers/my_controller.rb b/app/controllers/my_controller.rb index fc9f8ac5e9..a2fea7f163 100644 --- a/app/controllers/my_controller.rb +++ b/app/controllers/my_controller.rb @@ -70,18 +70,7 @@ class MyController < ApplicationController def account @user = User.current @pref = @user.pref - if request.patch? - @user.attributes = permitted_params.user - @user.pref.attributes = params[:pref] || {} - @user.pref[:no_self_notified] = (params[:no_self_notified] == '1') - if @user.save - @user.pref.save - @user.notified_project_ids = (@user.mail_notification == 'selected' ? params[:notified_project_ids] : []) - set_language_if_valid @user.language - flash[:notice] = l(:notice_account_updated) - redirect_to action: 'account' - end - end + write_settings(redirect_to: :account) end #Edit user's settings @@ -243,6 +232,21 @@ class MyController < ApplicationController false end + def write_settings(redirect_to:) + if request.patch? + @user.attributes = permitted_params.user + @user.pref.attributes = params[:pref] || {} + @user.pref[:no_self_notified] = (params[:no_self_notified] == '1') + if @user.save + @user.pref.save + @user.notified_project_ids = (@user.mail_notification == 'selected' ? params[:notified_project_ids] : []) + set_language_if_valid @user.language + flash[:notice] = l(:notice_account_updated) + redirect_to(action: "#{redirect_to}") + end + end + end + def get_current_layout @user.pref[:my_page_layout] || DEFAULT_LAYOUT.dup end