通过重定向使闪存哈希持久化 [英] getting the flash hash to persist through redirects
问题描述
我的基本用例是做一些处理,设置flash[:notice]
,然后重定向到一个新页面.据我所知,重定向重置了 flash 标签(如果我错了,请纠正我).有没有办法获得坚持?使用会话不是一种选择,我已经使用 cookie 解决了这个问题,但我认为必须有更好的方法.
My basic use case is do some processing, set flash[:notice]
, and then redirect to a new page. From what I can tell, redirects reset the flash tag (please correct me if I'm wrong). Is there a way to gain persistence? Using sessions isn't an option, and I have hacked around the problem using cookies, but I think there's got to be a better way.
推荐答案
Flash 散列仅在一次重定向或呈现中持续存在.所以你应该可以使用默认设置.
The flash hash persists for exactly one redirect or render. So you should be fine with the default settings.
如果你需要为另一个请求/重定向保留 flash 哈希,你可以调用 flash.keep.
If you need to keep the flash hash for another request/redirect, you can call flash.keep.
flash.keep # keep the entire flash hash around for an extra request.
flash.keep(:notice) # keep just flash[:notice] for an extra request.
这篇关于通过重定向使闪存哈希持久化的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!