ruby-on-railsruby-on-rails-4

How do flash messages work in Rails?


How does the framework associate flash messages with users? How does it know when to apply it, i.e. after redirect?

Imagine a situation when in between adding a flash and loading the page the user was redirected to there comes some totally unconnected Ajax request. Will the Rails apply flash notices to the Ajax request?


Solution

  • I don't think flash hashes are associated with users. They are stored in the sessions cookie on the user's browser in order to persist for the next request. For the request following that one the flash hash clears itself out.