Sessions
The flash
is just part of Rails' session cookie system:
The flash is a special part of the session which is cleared with each request
The session
is a cookie stored on the client system.
It is a hash
({key: "value"}
), which means you can store a number of different pieces of data inside it.
Rails reserves the flash
inside the session cookie (it can only be populated through your controllers). You can populate the various elements of the flash session -- it basically looks like this:
session: {
flash: {
notice: ""
error: ""
alert: ""
}
}
This is corroborated here:
@env[Flash::KEY] ||= Flash::FlashHash.from_session_value(session["flash"])
In its nature, the session
variable is temporary, as described here:
Anything you place in the flash will be exposed to the very next action and then cleared out
This means that each time your application serves a new request (IE the user reloads their browser), the flash will be updated.
Remember, the session is a cookie stored on the clients' system. Client systems can only be updated through a complete HTTP refresh.
--
To answer your question, it depends on how you're using render
.
If render
forms part of an HTTP refresh, the flash will be updated. If it is just to add a partial, it won't change the flash.
redirect_to
is self explanatory. link_to
invokes a new HTTP request, so the flash will be updated (unless it's bound to ajax).
Render
In the controller, render is often used to describe the "rendering" of a new action:
def create
render :new, notice: "New action"
end
Used in this context, the render action will invoke the same process as redirect_to
-- pushing the browser to load a new url.