Fork me on GitHub
#luminus
<
2018-08-22
>
agigao10:08:51

Hello Clojurians, I’m going through documentation and I’m having hard time grasping what is flash parameter here:

(defn home-page [{:keys [flash]}]
  (layout/render
    "home.html"
    (merge {:messages (db/get-messages)}
           (select-keys flash [:name :message :errors]))))

manutter5110:08:56

"Flash" in this context usually refers to a message that shows up just once, on the next page load. The idea being that something happens to either reload the page or jump to another page, and you want to tell the user something one time. Example: The user goes to the "Alerts" page, but when the page goes to load alerts, the server says "This user is not logged in." You want to tell the user to log in first, but if you put that message on the Alerts page, they'll never see it, because you're immediately jumping to the login page. So you put the "You must log in first" message into a flash message, and when the login page loads, there will (presumably) be code that checks for any flash message, and displays it.