When creating a website with rails, the defined variables etc. disappear immediately when the screen is changed. I think that instance variables such as @user have often died in one screen transition. I heard that __session and flash will live longer, so I want to see their lifespan! I wrote the article out of curiosity.
This time I made it forcibly on my PF, so it's a little hard to see.
It may be a difficult image, but it can be defined casually.
controller
def top
session[:life]="I am session. It is alive"
flash[:life]="I am flash. It is alive."
params[:life]="I'm params. It is alive."
end
View
<%= session[:life]%><br>
<%= flash[:life]%><br>
<%= params[:life]%><br>
<%= yield %>
Confirm that everyone is displayed.
As early as params take a breath.
Flash is also exhausted here.
name | lifespan |
---|---|
params | 1 transition kill |
flash | 2 transition kill |
session | Live until you kill |
If the user's login status is saved in session, You can also be convinced that you are logged in all the time. Logout was destroying the login status of the user saved in session.