diff options
Diffstat (limited to 'app/controllers/application_controller.rb')
-rw-r--r-- | app/controllers/application_controller.rb | 25 |
1 files changed, 17 insertions, 8 deletions
diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index 4e6ad5efb..8ef23f49d 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -42,18 +42,18 @@ class ApplicationController < ActionController::Base end def set_gettext_locale - requested_locale = params[:locale] || session[:locale] || cookies[:locale] || request.env['HTTP_ACCEPT_LANGUAGE'] + if MySociety::Config.get('USE_DEFAULT_BROWSER_LANGUAGE', true) + requested_locale = params[:locale] || session[:locale] || cookies[:locale] || request.env['HTTP_ACCEPT_LANGUAGE'] || I18n.default_locale + else + requested_locale = params[:locale] || session[:locale] || cookies[:locale] || I18n.default_locale + end session[:locale] = FastGettext.set_locale(requested_locale) end # scrub sensitive parameters from the logs filter_parameter_logging :password - helper_method :site_name, :locale_from_params - def site_name - site_name = MySociety::Config.get('SITE_NAME', 'Alaveteli') - return site_name - end + helper_method :locale_from_params # Help work out which request causes RAM spike. # http://www.codeweblog.com/rails-to-monitor-the-process-of-memory-leaks-skills/ @@ -223,7 +223,11 @@ class ApplicationController < ActionController::Base if session[:user_id].nil? return nil else - return User.find(session[:user_id]) + begin + return User.find(session[:user_id]) + rescue ActiveRecord::RecordNotFound + return nil + end end end @@ -274,7 +278,9 @@ class ApplicationController < ActionController::Base def check_read_only read_only = MySociety::Config.get('READ_ONLY', '') if !read_only.empty? - flash[:notice] = "<p>WhatDoTheyKnow is currently in maintenance. You can only view existing requests. You cannot make new ones, add followups or annotations, or otherwise change the database.</p> <p>" + read_only + "</p>" + flash[:notice] = _("<p>{{site_name}} is currently in maintenance. You can only view existing requests. You cannot make new ones, add followups or annotations, or otherwise change the database.</p> <p>{{read_only}}</p>", + :site_name => site_name, + :read_only => read_only) redirect_to frontpage_url end @@ -349,6 +355,9 @@ class ApplicationController < ActionController::Base # views (for links) and mailers (for use in emails), so include them into # all of all. include LinkToHelper + + # Site-wide access to configuration settings + include ConfigHelper end |