I have a lot of pages like this, so I should probably abstract out the code...
Derek Chen-Becker wrote: > There may be a better way, but your approach looks very reasonable. > > Derek > > On Fri, Mar 13, 2009 at 6:32 PM, Charles F. Munat <[email protected] > <mailto:[email protected]>> wrote: > > > Ha! I knew it would be simple. I should've tried that. But I was also > interested in finding out if anyone had a better idea for how to handle > this situation (as it is very common for the kind of sites I build). > > Thanks, Derek. You da man. > > Chas. > > Derek Chen-Becker wrote: > > I think it may be helpful to use a guard: > > > > case RewriteRequest(path @ > > ParsePath("bios" :: id :: _, _, _,_), _, _) if id != "index" => > > RewriteResponse( > > ParsePath("bio" :: "index" :: Nil, > > "", > > true, > > false), > > Map("id" -> id :: path.wholePath.drop(2) > > .zipWithIndex.map(p => > > ("param"+(p._2 + 1)) -> p._1) :_* > > ) > > ) > > > > The RewriteResponse class (not companion object, as you're using > here) > > also has a flag in the constructor to tell Lift to stop rewriting. > > > > Derek > > > > On Fri, Mar 13, 2009 at 5:34 PM, Charles F. Munat <[email protected] > <mailto:[email protected]> > > <mailto:[email protected] <mailto:[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) :_* > > ) > > ) > > > > 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. > > > > > > > > > > > > > > > > > --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
