fl00r
fl00r

Reputation: 83680

Where are flash messages stored?

I thought they were stored in cookies - but no, cookies inspecting gives me nothing. Sessions do not store them either. So, where I can find them?

I need this to set them directly (not through flash hash).

Upvotes: 9

Views: 7837

Answers (3)

Throw Away Account
Throw Away Account

Reputation: 2671

I was looking for a more detailed answer, and I ended up finding it through investigation. The following applies if your project is storing its session in a Postgres database.

NOTE: Your app may have connections to more than one DB. I still haven't figured out how Rails determines which of these connections to use. My project's session_store.rb is empty.

You'll find the flash messages in the sessions table. There is a column called data which contains a base64-encoded string.

If you decode the string, you'll find a binary blob which contains not just the flash messages (in marshalled form, so they can represent any type of Ruby object), but also the CSRF token, and several other things.

The whole blob is actually a marshalled hash table. It can be unmarshalled in Ruby with Marshal.load, and after any changes are made, it can be remarshalled with Marshal.dump.

Upvotes: 0

pdu
pdu

Reputation: 10423

According to APIdock : ActionController/Flash, it is stored in a session.

Note that if sessions are disabled only flash.now will work.

When using flash.now, your values are not available in the next request.

Upvotes: 3

Benoit Garret
Benoit Garret

Reputation: 13675

They are stored in your session store. The default since rails 2.0 is the cookie store, but check in config/initializers/session_store.rb to check if you're using something other than the default.

Upvotes: 11

Related Questions