views:

23

answers:

1

I've put some code like this

flash[:task_loader] = flash[:task_loader]
flash[:task_loader_params] = flash[:task_loader_params]

in a function in my controller which all my actions can call. This has the effect of keeping those two flash entries in the FlashHash. (I presume odd-looking code works because the '=' does more than just assign values.)

My question is, is there a better way to do this? Something like

flash[:task_loader].pin
A: 

Flash is a convenient wrapper for storing data in cookies and expiring them in the next request. So that your notification messages will work through 2 (or multiple) request response cycles.

If you want some more persistence, you can use session:

session[:task_loader] = my_task_loader

Note that one cookie can hold only 4KB of data.

(I presume odd-looking code works because the '=' does more than just assign values.)

This is because it is not simply an assignment, but a method []=, with a signature similar to this:

def []=(k, v)
Swanand
I'm using the flash in this case to store information on what to load when an AJAX request is made to reload a list of items on the current page. I can't user the session - my app gets confused when making AJAX calls from pages drawn from the browser's history.
Ben