I am trying to find a way to deal with rails (v4.1) flash messages when using turbolinks 5.
I tried adding data-temporary="true"
to each flash message div and then something like:
$(document).on('turbolinks:before-cache', function () {
$('[data-temporary]').remove();
});
so old flash messages aren't cached and won't be shown the next time the user accesses that same page.
However, that has left me with an issue on pages where I'm using flash.now
because on these pages the flash has been removed from the cached version but then turbolinks refreshes the content from the server and the flash.now
message then appears which is a bit jarring from a user point of view.
I've had a look around and can't find anything for flashes to indicate if they are .now
or not so that data-temporary
could just be applied to temporary ones.
I'm trying to work with turbolinks rather than disable its functionality.
I'm trying to find a way to remove flashes before-cache
but not if they are flash.now
type.
Any suggestions?
what about sending the flash.now with a different symbol so you can diferentiate them from the ones you need to remove. for example
flash.now[:dont_remove_me_please] = "Could not save client"
with that you can check the "type", and exclude them from the remove.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With