Extra params for a handler inside Ring's wrap-params

22 views
Skip to first unread message

Thorsten Wilms

unread,
Mar 23, 2011, 9:32:22 AM3/23/11
to clo...@googlegroups.com
Hi!

Routing, using ring.middleware.params and net.cgrand.moustache:
----
(def tlog-app-handler
(app ["admin" &]
{:get (app ...snip...)
:post (app wrap-params [[path not-empty] &] submit-article)}
----

Thanks to wrap-params, I can destructure request params within
submit-article. However, I also want to have "path". Without
wrap-params, it would simply be:
----
(app [[path not-empty] &] (submit-article path))
----

----
(app wrap-params [[path not-empty] &] (partial submit-article path))
----
results in "nth not supported on this type: PersistentHashMap"

assoc-param (see
http://mmcgrana.github.com/ring/middleware.params-api.html) looks like
it could be what I need, but I can't find out how to use it in this
context (what wraps what and what is the right "map"?)

I realize that I could extract "path" from the request map, but I would
prefer a solution where what has been taken apart already is used,
instead of repeating that work.


--
Thorsten Wilms

thorwil's design for free software:
http://thorwil.wordpress.com/

Thorsten Wilms

unread,
Mar 24, 2011, 9:09:08 AM3/24/11
to clo...@googlegroups.com
On 03/23/2011 02:32 PM, Thorsten Wilms wrote:
> Hi!
>
> Routing, using ring.middleware.params and net.cgrand.moustache:
> ----
> (def tlog-app-handler
> (app ["admin" &]
> {:get (app ...snip...)
> :post (app wrap-params [[path not-empty] &] submit-article)}
> ----
>
> Thanks to wrap-params, I can destructure request params within
> submit-article. However, I also want to have "path". Without
> wrap-params, it would simply be:
> ----
> (app [[path not-empty] &] (submit-article path))
> ----
>
> ----
> (app wrap-params [[path not-empty] &] (partial submit-article path))
> ----
> results in "nth not supported on this type: PersistentHashMap"

Should have been:
----
(app [[path not-empty] &] (wrap-params (partial submit-article path)))
----
Which works, then.

Thanks to the fine folks in #clojure, I have another solution:
----
(app [[path not-empty] &] (wrap-params
(fn [req] (submit-article req path))))
----

Reply all
Reply to author
Forward
0 new messages