]> git.openstreetmap.org Git - rails.git/blob - app/controllers/preferences_controller.rb
Merge branch 'master' into feature/add-communities-page
[rails.git] / app / controllers / preferences_controller.rb
1 class PreferencesController < ApplicationController
2   layout "site"
3
4   before_action :authorize_web
5   before_action :set_locale
6
7   authorize_resource :class => false
8
9   before_action :check_database_readable
10   before_action :check_database_writable, :only => [:update]
11
12   def show; end
13
14   def edit; end
15
16   def update
17     current_user.languages = params[:user][:languages].split(",")
18
19     current_user.preferred_editor = if params[:user][:preferred_editor] == "default"
20                                       nil
21                                     else
22                                       params[:user][:preferred_editor]
23                                     end
24     if current_user.save
25       # Use a partial so that it is rendered during the next page load in the correct language.
26       flash[:notice] = { :partial => "preferences/update_success_flash" }
27       redirect_to preferences_path
28     else
29       flash.now[:error] = t ".failure"
30       render :edit
31     end
32   end
33 end