This blog is part of our Rails 5 series.
Rails, by default, stores session data in cookies.
The cookies have a storage limit of 4K and cookie overflow exception is raised if we attempt to store more than 4K of data in it.
Cookie overflow issue with Rails 4.x
Flash messages are persisted across requests with the help of session storage.
Flash messages like
are marked as discarded for next request.
So, on next request, it gets deleted before
reconstituting the values.
This unnecessary storage of discarded
flash messages leads
to more consumption of data in the cookie store.
When the data exceeds 4K limit,
Let us see an example below to demonstrate this.
In the above example,
it might be possible that
params[:search] is large amount of data
as the session
Rails 5 removes discarded flash messages
In Rails 5,
discarded flash messages are removed
before persisting into the session
leading to less consumption of space
and hence, fewer chances of
We can see from above example,
flash.now value is not added in session in Rails 5
leading to less chances of raising