Optimisation: pages are displayed without layout, when called from a xhr request.

Should be useful to speed up paginations
This commit is contained in:
echarp 2018-09-02 19:10:37 +02:00
parent 69dcb84780
commit a9c5d6bc55
2 changed files with 8 additions and 1 deletions

View File

@ -5,6 +5,8 @@ class ApplicationController < ActionController::Base
# For APIs, you may want to use :null_session instead. # For APIs, you may want to use :null_session instead.
protect_from_forgery prepend: true, with: :exception protect_from_forgery prepend: true, with: :exception
layout :handle_xhr_layout
private private
def set_locale def set_locale
@ -26,4 +28,9 @@ class ApplicationController < ActionController::Base
def set_mailer_host def set_mailer_host
ActionMailer::Base.default_url_options[:host] = request.host_with_port ActionMailer::Base.default_url_options[:host] = request.host_with_port
end end
# If the request is an xhr, we don't render any layout
def handle_xhr_layout
request.xhr? ? false : 'application'
end
end end