I thought they were stored in cookies - but no, cookies inspecting gives me nothing. Ses开发者_开发知识库sions do not store them either. So, where I can find them?
I need this to set them directly (not through flash
hash).
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.
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.
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
.
精彩评论