Flash messages in Joodo

September 11, 2012

Joodo has built in support for Rails-like flash messages.
These are great for persisting one-time messages between requests.

First off we need to set the message in the controller.

(defn- create-user []
  (let [params (:params *request*)]
    (save (hash-map :kind "user" :name (:name params)))
    (assoc
      (redirect-after-post "/")
      :flash {:messages ["User Created!"]})))

Now we can grab this flash message from our view.

(if-let [flash (:flash *request*)]
  [:div {:class "flash"}
    (if-let [messages (:messages flash)]
      [:div {:class "messages"}
        (map #(identity [:div {:class "message"} %]) messages)])])

Profile picture

Written by Eric Koslow a programmer with too much time on his hands You should follow them on Twitter