I sometimes use flash to keep things between multiple request ex.
searched word and use FlashHash#keep in before filter to keep it when
user is still using the same controller.
Can you provide more info on what you’re doing with this searched word? Highlighting?
My initial reaction is it’s a dubious practice, because it relies on the user visiting the same controller action in the next request. If they open a page in another tab, for instance, it’d get messed up.
I’d usually favor embedding that parameter in the form for the next request (e.g., for a search form, prepopulate the query box with the searched word). If you want it to persist for longer, then perhaps cookie/session storage makes more sense.
How can I keep something for
the next request when rendering in your proposed solution? Would I
have to set flash and keep it in the same request ?
flash[:keyword] = “searched term”
Something like that. Or even:
flash.keep[:keyword] = ‘searched term’
i.e., keep the common case clean, at the expense of making the unusual case a bit more work.
Thanks for your input.