From a9c5d6bc552185deb527bbba92dfecc10702eec3 Mon Sep 17 00:00:00 2001 From: echarp Date: Sun, 2 Sep 2018 19:10:37 +0200 Subject: [PATCH] Optimisation: pages are displayed without layout, when called from a xhr request. Should be useful to speed up paginations --- app/assets/javascripts/events.js.coffee | 2 +- app/controllers/application_controller.rb | 7 +++++++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/app/assets/javascripts/events.js.coffee b/app/assets/javascripts/events.js.coffee index 9b8a3530..6f0e9971 100644 --- a/app/assets/javascripts/events.js.coffee +++ b/app/assets/javascripts/events.js.coffee @@ -6,7 +6,7 @@ $(document).on 'turbolinks:load', -> if $('#event_start_time').val() >= $('#event_end_time').val() $('#event_start_time').val($('#event_end_time').val()) - # Quick mechanism so that the ice cube rule only appears when useful + # Quick mechanism so that the ice cube rule only appears when useful $('#event_repeat').each -> if $(this).val() == '0' $('.field.rule').hide() diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index c9bf4b1c..2647aac8 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -5,6 +5,8 @@ class ApplicationController < ActionController::Base # For APIs, you may want to use :null_session instead. protect_from_forgery prepend: true, with: :exception + layout :handle_xhr_layout + private def set_locale @@ -26,4 +28,9 @@ class ApplicationController < ActionController::Base def set_mailer_host ActionMailer::Base.default_url_options[:host] = request.host_with_port end + + # If the request is an xhr, we don't render any layout + def handle_xhr_layout + request.xhr? ? false : 'application' + end end