James,

I even tried the examples you gave me:

(defroutes main-routes
    (GET "/" [] (welcome))
    (GET "/form" [] (render-form))
    (GET "/login/" [] (login-view))
;   (POST "/login/" {request :request params :params} (login-
controller request params))
    (POST "/login/" {params :params session :session} (login-
controller params session))
;   (ANY "/logout/" [] (logout-controller session))
    (ANY "/page/" {request :request session :session} (page request
session "hello" "world"))
    (GET "/a" [] (ooops))
    (GET "/set" [x :as {session :session}]
      {:session (assoc session :x "Shree")
      :body (str "You set x = " x)})
    (GET "/get" {session :session}
      (str "x = " (:x session)))
    (POST "/form" {params :params} (handle-form params))
    (route/not-found (page_not_found)))

But for WHATEVER reason, the sessions are NOT getting stored? When I
goto the set page, I get:

http://localhost:3000/set
  You set x =

-and-

http://localhost:3000/get
  x =

respectively. I must REALLY be messing SOMETHING up at my end???  Why
else would this NOT be working???

Thanks,

shree


On May 11, 8:01 pm, James Reeves <jree...@weavejester.com> wrote:
> On 12 May 2011 00:04, Shree Mulay <shreemu...@gmail.com> wrote:
>
> > From this code, I can't figure out where you "instantiate" the session
> > var, store to it, and read back from it? I know there's not
> > instantiation in clojure(???). I hope your able to get what I'm having
> > trouble figuring out.
>
> The session is read from a :session key on the request map, and
> written using a :session key on the response map.
>
> For example, this route returns the value of the session key :x
>
>   (GET "/get" {session :session}
>     (str "x = " (:x session)))
>
> It's equivalent to the Sinatra route:
>
>   get "/get" do
>     "x = #{session[:x]}"
>   end
>
> The main difference is that the session has to be bound explicitly. We
> don't just get a magic session map hanging around in the background.
>
> Writing a session is a little trickier:
>
>   (GET "/set" [x :as {session :session}]
>     {:session (assoc session :x x)
>      :body (str "You set x = " x)})
>
> The equivalent Sinatra route is:
>
>   get "/set" do |x|
>     session[:x] = x
>     "You set x = #{x}"
>   end
>
> Ring sessions are a little unwieldy because you write by changing the
> response, rather than calling a side-effectful function. Sandbar takes
> a slightly different approach that looks more like the Sinatra code:
>
>   (GET "/get" []
>     (str "x = " (session-get :x)))
>
>   (GET "/set" [x]
>     (session-put! :x x)
>     (str "You set x = " x))
>
> Sandbar is a little cleaner for simple things, but Ring sessions have
> the advantage of working well with middleware. Idiomatic Ring tends to
> use a lot of middleware, far more than one might use in Rack (for
> instance).
>
> - James

-- 
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en

Reply via email to