From 68c07f49cf12c2872fe1b88dede116334445542a Mon Sep 17 00:00:00 2001 From: Sebastian Serth Date: Thu, 22 Nov 2018 18:59:07 +0100 Subject: [PATCH 1/2] Show flash messages based on `turbolinks:load` instead of real page load --- lib/assets/javascripts/flash.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/assets/javascripts/flash.js b/lib/assets/javascripts/flash.js index 7f53f2bb..d7273864 100644 --- a/lib/assets/javascripts/flash.js +++ b/lib/assets/javascripts/flash.js @@ -1,4 +1,4 @@ -(function() { +$( document ).on('turbolinks:load', function() { var DURATION = 10000; var SEVERITIES = ['danger', 'info', 'success', 'warning']; @@ -48,4 +48,4 @@ generateMethods(); $(showFlashes); -})(); +}); From c4f9c2fc85a7ebaae6198ab98f74f5c18231ff16 Mon Sep 17 00:00:00 2001 From: Sebastian Serth Date: Thu, 22 Nov 2018 19:00:01 +0100 Subject: [PATCH 2/2] Prevent redirection if possible This will just show the flash message on prevent the browser from changing the location. Works great with Turbolinks! --- app/controllers/application_controller.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index 91601b0b..67c4742e 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -15,7 +15,7 @@ class ApplicationController < ActionController::Base end def render_not_authorized - redirect_to(:root, alert: t('application.not_authorized')) + redirect_to(request.referrer || :root, alert: t('application.not_authorized')) end private :render_not_authorized