Yes, that certainly did help. Can't believe I didn't see this and it still 
flew over my head when others pointed it out. 

Looks a bit hacky, but this is the result I came up with (for future 
person's reference): 

(GET  "/:profile-page" [profile-page]
        (if (= (.indexOf profile-page " ") -1)
          (let [profile-page (clojure.string/replace profile-page #"-" " ")]
            (let [[{user-profile :handle}] (db/get-users profile-page)]
              (if (not (nil? user-profile))
                (layout/page-top
                 (str profile-page"'s Profile Page")
                 (profile/profile-page profile-page)))))))


It's sort of the finishing touches on a relatively complete project. Of 
course, gotta mind those anchors (thanks for that reminder, lest I'd see 
everything blow up). 

Thank you everyone for the time and patience. 

On Monday, March 10, 2014 11:00:32 PM UTC-7, Jarrod Swart wrote:
>
> No edit button so I have to post again, that first example should end with 
> ";; (make-profile-url "John Smith") => "/John-Smith"
>
> And to reiterate you decide what your url will look like in your template:
>
> <a href="http://myapp.com/JohnSmith";>View John Smith's Profile</a>
> or
> <a href="http://myapp.com/John-Smith";>View John Smith's Profile</a>
> or
> <a href="http://myapp.com/john-smith";>View John Smith's Profile</a>
>
> Then compojure + your route handler respond to the browser requesting the 
> link:
>
> ;; obviously this is ALL just psedo code of the important elements to give 
> you an idea
> (GET "/:username" [username] (view-profile-page username)) ;; this route 
> definition will handle any of the above links
>
> ;; assume you chose the last link type, in stack-overflow style. this 
> means username from the route is "john-smith"
> (defn view-profile-page [username]
>   (let [user (db/get-user-by-username username)]
>     (render-template user)))
>
> (defn get-user-by-username [username]
>   (let [no-dash (clojure.string/replace username #"-" " ") ;; munge 
> username to match what is in DB
>          capitalized (capitalize-words no-dash)]
>     (select-user-by-name capitalized)))
>
> So as you can see whatever link or browser request is called, compojure 
> grabs that url param and passes it in.  You then modify that param to fit 
> what you expect and look it up in your DB.  You were essentially working 
> backwards I think.
>
> Hope that helps!
>
>

-- 
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
--- 
You received this message because you are subscribed to the Google Groups 
"Clojure" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to clojure+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to