Skip to content

Instantly share code, notes, and snippets.

@ccollins
Created January 19, 2010 18:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ccollins/281129 to your computer and use it in GitHub Desktop.
Save ccollins/281129 to your computer and use it in GitHub Desktop.
(defmacro gen-controllers [resource views]
`(let [res-name# (name ~resource)
index# (str res-name# "-index")]
(list
(defn index# []
((~views :index) (mongo/fetch-all col)))
(defn c-show [id#]
((~views :show) (mongo/fetch-by-id col id#)))
(defn c-new []
(~views :new))
(defn c-create [params#]
(mongo/insert col params#)
(redirect-to (str "/" ~resource)))
(defn c-edit [id#]
((~views :edit) (mongo/fetch-by-id col id#)))
(defn c-update [id# params#]
(mongo/update col (mongo/fetch-by-id col id#) {:$set params#})
(redirect-to (str "/" ~resource "/" id#)))
(defn c-delete [id#]
(mongo/delete col (mongo/fetch-by-id col id#))
(redirect-to (str "/" ~resource))))
))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment