Skip to content

Instantly share code, notes, and snippets.

@kumarshantanu
Created September 3, 2010 07:38
Show Gist options
  • Star 4 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kumarshantanu/563552 to your computer and use it in GitHub Desktop.
Save kumarshantanu/563552 to your computer and use it in GitHub Desktop.
(ns example.flash
(:use compojure.core)
(:use ring.util.response)
(:use ring.middleware.session)
(:use ring.middleware.flash)
(:require [compojure.route :as route]))
(defn show-new [flash]
(str "Flash: " flash
"<br/>
<form method='POST' action='/news'>
<input type='submit' value='Success'>
</form>
<form method='POST' action='/newf'>
<input type='submit' value='Error'>
</form>"))
(def flash-success {:flash {:success "Success"}})
(def flash-error {:flash {:error "Failed"}})
(defroutes handler
(GET "/" [] "<h1>Hello World Wide Web!</h1>")
(GET "/new" {flash :flash} (show-new flash))
(POST "/news" {params :params} (merge (redirect "/new") flash-success))
(POST "/newf" {params :params} (merge (redirect "/new") flash-error))
(route/not-found "Page not found"))
(def app (wrap-session (wrap-flash handler)))
(defonce x (future (run-jetty (var app) {:port 8088})))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment