]> git.openstreetmap.org Git - rails.git/blobdiff - app/controllers/preferences_controller.rb
Make a generic preferred color scheme method
[rails.git] / app / controllers / preferences_controller.rb
index 6839bf37a8058302907fb700a832ad293f406854..f002d5d395d045307735fbf874dee70eefa71c1a 100644 (file)
@@ -21,11 +21,20 @@ class PreferencesController < ApplicationController
                                     else
                                       params[:user][:preferred_editor]
                                     end
                                     else
                                       params[:user][:preferred_editor]
                                     end
-    if current_user.save
-      flash[:notice] = t ".success"
+
+    success = current_user.save
+
+    if params[:site_color_scheme]
+      site_color_scheme_preference = current_user.preferences.find_or_create_by(:k => "site.color_scheme")
+      success &= site_color_scheme_preference.update(:v => params[:site_color_scheme])
+    end
+
+    if success
+      # Use a partial so that it is rendered during the next page load in the correct language.
+      flash[:notice] = { :partial => "preferences/update_success_flash" }
       redirect_to preferences_path
     else
       redirect_to preferences_path
     else
-      flash[:error] = t ".failure"
+      flash.now[:error] = t ".failure"
       render :edit
     end
   end
       render :edit
     end
   end