This worked with Compojure 4.1, not with 6.4

32 views
Skip to first unread message

David Cabana

unread,
Jul 13, 2011, 1:50:53 PM7/13/11
to Compojure
I just started using Compojure, and am trying to figure out how to
work with forms. I managed to cobble together a small sample app that
reads a text entry. It works with Compojure 4.1 but not 6.4. Here
is the code:

(ns forms.text
(:use [ring.adapter.jetty :only [run-jetty]]
[hiccup.core]
[hiccup.page-helpers]
[hiccup.form-helpers]
[compojure.core ] ))

(defn page [ & content]
(html
(doctype :html5)
[:head [:title "title"]]
[:body content ]))

(defn form-page [ & a]
(page
[:form {:method "post" :action "/"}
[:input {:type "text" :name "a" :value a}]
[:input {:type "submit" :value "enter some text..."}]] ))

(defroutes my-routes
(GET "/" [] (form-page))
(POST "/" [a]
(if (nil? a)
(page [:h2 "Error: could not read data ..."])
(page [:h2 (str a)]))))

Notice the POST section. Using 6.4 I get the first alternative, using
4.1 I get the second. Any help getting it to work with 6.4 would be
much appreciated, as would any pointers to working sample code using
forms.

BTW, these are the complete lein dependencies:
:dependencies [[org.clojure/clojure "1.2.1"]
[org.clojure/clojure-contrib "1.2.0"]
[hiccup "0.3.6"]
[ring/ring-jetty-adapter "0.3.10"]
[compojure "0.4.1"]]


Thanks,
David

Joe Snikeris

unread,
Jul 13, 2011, 2:57:08 PM7/13/11
to comp...@googlegroups.com

<snip>

Hi David,

I just set up a project using the configuration you've listed above
(plus lein-ring to run it).

I'm not getting the "Error: could not read data ..." message like
you've indicated.

I would suggest using Firebug to see what exactly your browser is
posting to jetty.

Regards,
Joe

James Reeves

unread,
Jul 13, 2011, 2:58:08 PM7/13/11
to comp...@googlegroups.com
On 13 July 2011 18:50, David Cabana <drca...@gmail.com> wrote:
> I just started using Compojure, and am trying to figure out how to
> work with forms. I managed to cobble together a small sample app that
> reads a text entry.  It works with Compojure 4.1 but not 6.4.   Here
> is the code:

Have you checked the "Breaking Changes" section of the README?

As of 0.6.0, Compojure no longer adds default middleware to routes,
but it does provide some helper functions in the compojure.handler
namespace.

Try adding the following and using it as your handler:

(def app
(compojure.handler/site my-routes))

- James

Joe Snikeris

unread,
Jul 13, 2011, 3:03:48 PM7/13/11
to comp...@googlegroups.com
On Wed, Jul 13, 2011 at 2:57 PM, Joe Snikeris <j...@snikeris.com> wrote:
> On Wed, Jul 13, 2011 at 1:50 PM, David Cabana <drca...@gmail.com> wrote:

<snip>

>>
>> (defroutes my-routes
>>  (GET "/" [] (form-page))
>>  (POST "/" [a]
>>        (if (nil? a)
>>          (page [:h2 "Error: could not read data ..."])
>>          (page [:h2 (str a)]))))
>>
>> Notice the POST section.  Using 6.4 I get the first alternative, using
>> 4.1 I get the second.   Any help getting it to work with 6.4 would be
>> much appreciated, as would any pointers to working sample code using
>> forms.
>>
>> BTW, these are the complete lein dependencies:
>>  :dependencies [[org.clojure/clojure "1.2.1"]
>>                 [org.clojure/clojure-contrib "1.2.0"]
>>                 [hiccup "0.3.6"]
>>                 [ring/ring-jetty-adapter "0.3.10"]
>>                 [compojure "0.4.1"]]
>>
>
> <snip>
>
> Hi David,
>
> I just set up a project using the configuration you've listed above
> (plus lein-ring to run it).
>
> I'm not getting the "Error: could not read data ..." message like
> you've indicated.

My bad. When I change project.clj to depend on Compojure 0.6.4, I do
get your error message.

David Cabana

unread,
Jul 13, 2011, 9:02:28 PM7/13/11
to comp...@googlegroups.com
James, Joe,

Thank you for your help. James, I saw the breaking changes note, but
I am very new to Compojure, and did not have enough context to connect
the dots. I appreciate being pointed in the right direction.

David

Reply all
Reply to author
Forward
0 new messages