On Fri, Mar 13, 2009 at 10:34 PM, Charles F. Munat <[email protected]> wrote:

>
> I have a lot of sites that involve dynamically-generate pages. OK, all
> of them do. So let's say that I have a "bios" page where I link to a
> bunch of individual bios (for Sam, Sally, and Sue). If Sam is user #1
> and Sally and Sue are #2 and #3 respectively, I want to get to their
> bios like this:
>
> /bios                   -> Bio index page
> /bios/1                 -> Sam's bio
> /bios/2                 -> Sally's bio
> /bios/3                 -> Sue's bio
>
> Yes, I know about exposing database IDs. I don't care. But sometimes I
> do something like this:
>
> /bios
> /bios/sam_spade
> /bios/sally_struthers
> /bios/sue_me
>
> Where I generate the "code" from the users name using a regex. I
> actually like this better because it's more human readable, but
> generating the codes is a bitch (and names aren't always unique). So I
> get lazy and go back to numbers.
>
> Currently, I do this:
>
> case RewriteRequest(path @
>     ParsePath("bios" :: id :: _, _, _,_), _, _) =>
>         RewriteResponse(
>             ParsePath("bio" :: "index" :: Nil,
>                       "",
>                       true,
>                       false),
>             Map("id" -> id :: path.wholePath.drop(2)
>                 .zipWithIndex.map(p =>
>                     ("param"+(p._2 + 1)) -> p._1) :_*
>             )
>         )


Note that:
case class RewriteResponse(path: ParsePath, params: Map[String, String],
stopRewriting: Boolean)

Takes a third parameter, a boolean that if true will stop any more
re-writing, although I think Derek's solution is better.



>
>
> Then I put the template for the bio page in /bio/index.html.
>
> The problem here is that I can't use /bio/index.html as the "index" page
> for the bios (choosing a template) because I get an infinite loop, which
> is why it redirects to /bio not /bios. I need it to *not* redirect when
> the "id" part is "index." There is probably a drop dead simple way to do
> this, but my brain is fried after five all-nighters this week.
>
> Also, is this really the best way to implement the behavior I describe
> at the beginning of this email? And does everyone understand why I'm not
> using /bios/?F5177147114085ON=_ ?
>
> Chas.
>
> >
>


-- 
Lift, the simply functional web framework http://liftweb.net
Beginning Scala http://www.apress.com/book/view/1430219890
Follow me: http://twitter.com/dpp
Git some: http://github.com/dpp

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Lift" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/liftweb?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to