> >http://github.com/Ejhfast/Cloggerhttp://preview.compojure.org/docs/mi...
>
> > I hope someone can help.
>
> > Thanks!
I am doing something similar but this doesn't seem to work for me
either, OTOH,
returning a map like {:session <modified session map>, :body ...etc.}
works just fine,
for example, I would have to use:
[302 :session (session-assoc :user user) :Location "/"]
but this doesn't:
(session-assoc :user user)
(redirect-to "/")
Am I missing something here?
> for example, I would have to use:
> [302 :session (session-assoc :user user) :Location "/"]
> but this doesn't:
> (session-assoc :user user)
> (redirect-to "/")
> Am I missing something here?
Make sure you have the two forms in a vector:
[ (session-assoc :user user)
(redirect-to "/") ]
If I'm following the Compojure code correctly, (session-assoc) doesn't
change the session when you call it. Instead, it returns a function
that later gets invoked to build the response, and that's when the
session picks up the change. Hence the vector, to make sure the
returned function is part of the response along with the redirect.
On Dec 17, 8:37 am, Bob Follek <bfol...@gmail.com> wrote:
> Make sure you have the two forms in a vector:
>
> [ (session-assoc :user user)
> (redirect-to "/") ]
>
Yes, that's the confusing part. People coming from other frameworks
are accustomed to have read/write access to session from any part of
their code. It is hard to understand why you have to do it in specific
part.
It is an artificial requirement of this specific web framework.
The original idea was to make session modification functional, so
instead of modifying the session directly, you return a delta of how
you want the session to change along with the response. This approach
does have some benefits, but I'm beginning to think that the
disadvantages outweigh the advantages in this case.
You may know that I plan to factor most of Compojure's functionality
out into independent libraries. Session support will probably be
altered to use side-effect functions and then factored out into a
"ring-sessions" library. So I do plan to change the API eventually.
However, I personally prefer the REST model for constructing web
applications, so sessions (being rather unRESTful) aren't really too
high on my list of priorities. If someone else wants to work on the
session library, I welcome any help.
- James