On 4/2/07, Ben Bangert <[EMAIL PROTECTED]> wrote:
>
> On Apr 2, 2007, at 5:20 PM, Mike Orr wrote:
>
> > This is probably a Pylons problem rather than Routes.  I have a
> > routing rule like this:
> >
> >     map.connect("glossary", "/glossary/:page", controller="main",
> >         action="glossary", page="index")
> >
> > h.url_for("glossary")  generates "/glossary" rather than the expected
> > "/glossary/".  When the user clicks on the link, Pylons serves the
> > index page directly rather than redirecting to "/glossary/" like
> > Apache and other frameworks do.  This breaks any relative links on the
> > page because a link to "foo" will resolve to "/foo" instead of
> > "/glossary/foo".
>
> That's intentional and required behavior for the concept of minimal
> URL's:
> http://routes.groovie.org/manual.html#minimum-urls
>
> Consider the example there, if your page assumes its 2 levels deep,
> but you have defaults, then you can get a URL that even if it had a
> trailing /, wouldn't be in the right directory that you had assumed.

I'm not sure what you mean.  What directory would you get and what
would you expect?

If /content/view/4 is a file, then /content/view and /content are
invalid URLs because they are directories; the proper URLs should be
/content/view/ (shorthand for /content/view/index) and /content/
(shorthand for /content/index).

> url_for and Routes has the concept of Route memory to avoid the need
> for relative URL's entirely. Ie, if you're at /content/view/4 and
> need to link to '3', you can just do url_for(id=3). This is assuming
> the example shown at the minimum-url's bit.

Why not?  If you have <a href="3"> on /content/view/4, it would link
to /content/view/3.  So why shouldn't Routes do the same thing?

> If you really want to use relative links, don't provide defaults for
> dynamic parts present in the URL. That's the only real way you can
> guarantee the URL will be in the right directory. Ie, if you change
> your map.connect statement to:
>
> map.connect("glossary", "/glossary/:page", controller="main",
> action="glossary")
>
> Then all your URL's will definitely have the /glossary/ section, and
> the shortest valid URL will be /glossary/index.

But then I can't do url_for("glossary") and get the main glossary
page, whatever it is.

I didn't know you could do url_for(id=3) at all; that's nifty.  I did
switch to url_for for all my intra-glossary links, because
url_for("glossary") generates relative-incompatible links.

-- 
Mike Orr <[EMAIL PROTECTED]>

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"pylons-discuss" 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/pylons-discuss?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to