What is flash in Rails?

Answer

The Rails flash is a special part of the session that stores a message only for the next request — it is cleared afterwards. Commonly used to show success or error notices after a redirect. Example: flash[:notice] = "Post created successfully!" before redirect_to @post. In the view: <%= flash[:notice] %>. flash.now is used when rendering (not redirecting) so the message is available for the current request only: flash.now[:alert] = "Invalid credentials". Flash prevents stale messages from persisting across multiple requests.