2014-08-06 14:47:47 +02:00
|
|
|
# The top level controller, where can be centralised almost everything
|
2013-11-13 23:09:38 +01:00
|
|
|
class ApplicationController < ActionController::Base
|
2019-02-06 09:34:39 +01:00
|
|
|
before_action :set_paper_trail_whodunnit, :set_locale, :discard
|
2019-05-10 15:33:19 +02:00
|
|
|
before_action :set_mailer_host, if: :devise_controller?
|
2013-11-13 23:09:38 +01:00
|
|
|
# Prevent CSRF attacks by raising an exception.
|
|
|
|
# For APIs, you may want to use :null_session instead.
|
2017-11-11 12:44:09 +01:00
|
|
|
protect_from_forgery prepend: true, with: :exception
|
2014-09-20 17:20:40 +02:00
|
|
|
|
2018-10-17 15:47:43 +02:00
|
|
|
preserve :region, :tag, :near
|
|
|
|
|
2018-09-02 19:10:37 +02:00
|
|
|
layout :handle_xhr_layout
|
|
|
|
|
2014-09-20 17:20:40 +02:00
|
|
|
private
|
|
|
|
|
|
|
|
def set_locale
|
2015-11-10 23:29:05 +01:00
|
|
|
I18n.locale =
|
|
|
|
http_accept_language.compatible_language_from I18n.available_locales
|
2014-09-20 17:20:40 +02:00
|
|
|
end
|
2014-11-05 21:25:18 +01:00
|
|
|
|
2018-10-17 15:47:43 +02:00
|
|
|
# Mechanism to manage filter resets
|
|
|
|
def discard
|
|
|
|
params.keys.keep_if { |key| params[key].empty? }
|
|
|
|
.each { |key| session.delete ['application', key].join '_' }
|
2017-07-14 17:50:13 +02:00
|
|
|
end
|
|
|
|
|
2014-11-05 21:25:18 +01:00
|
|
|
protected
|
|
|
|
|
|
|
|
# Useful to manage absolute url in mails
|
|
|
|
def set_mailer_host
|
|
|
|
ActionMailer::Base.default_url_options[:host] = request.host_with_port
|
|
|
|
end
|
2018-09-02 19:10:37 +02:00
|
|
|
|
|
|
|
# If the request is an xhr, we don't render any layout
|
|
|
|
def handle_xhr_layout
|
|
|
|
request.xhr? ? false : 'application'
|
|
|
|
end
|
2013-11-13 23:09:38 +01:00
|
|
|
end
|