Created
September 3, 2010 07:38
-
-
Save kumarshantanu/563552 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(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