Rails turbolinks 5 flash messages

北战南征 提交于 2019-12-08 16:27:37

问题


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?


回答1:


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.



来源:https://stackoverflow.com/questions/42542471/rails-turbolinks-5-flash-messages

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!