[Rg 48] Re: Slightly irritating template bug

Michael Fellinger m.fellinger at gmail.com
Sun Jul 8 07:03:21 EDT 2007


On 7/8/07, Lars Olsson <lasso at lassoweb.se> wrote:
> Hi!
>
> I'm nothing a slightly irritating "bug" when using multiple Controllers
> and templates in Ramaze. Lets say I have the following Controller map:
>
> / => MainController
> /foo => FooController
>
> I also have the following file structure in my "public" dir (mirroring
> the controller map):
>
> public
>      css
>      images
>      foo
>        css
>        images
>
> Now, lets say I have he following HTML snippets in my foo/index.xhtml
> template:
>
> <link rel= "StyleSheet" type="text/css" href="css/foo.css"/>
> <img src="images/foo.png"/>
>
> Let's fire up the web browser and try the following two urls:
>
> http://mysite/foo
> http://mysite/foo/ (notice trailing slash)
>
> In both cases the right Controller (FooController) gets called, but in
> the first case "relative" links (like in the html snippets above)
> doesn't work as intended. If I look at the console I can see:
>
> [2007-07-08 11:18:49] ERROR  #<Ramaze::Error::NoAction: No Action found
> for `/css/foo.css' on MainController>
>
> So, even though the FooController renders the template, it looks like
> the MainController gets called on all the "relative" stuff in the template.
>
> Since it's hard to force anyone to use a trailing slash when browsing
> the web, I think the current behavior is a bug. There are of course ways
> around the problem....I could stop using relative links. Another way is
> to redirect the index action to another action, but neither of those
> solutions seems "the right thing to do".
>
> What do you think? Is it a bug or intended behavior? Is it fixable?

If we speak about the internal handling, "/" is replaced by "/index",
that is why you can have a def index in your controller. Talking about
browsers, there just is no way they always append the trailing slash,
so putting out links to /index might be the easiest solution. The
other, much more common is to use absolute hrefs, i know this may
somehow clash with your application and i'm really sorry about that,
but URIs are tricky and the request that we get is for the absolute
path figured out by the browser, we could start wild guessing when
searching for a possible match but that would again decrease
performance on serving files...

It's a tricky problem and no matter how i look at it currently it just
doesn't seem to be possible to solve. Either you have to put in
absolute URIs to your files (like, as you may see, do just about all
pages that use the so-called 'pretty urls') or you explicitly point
people to a /index page, just saving them the '.html' - which doesn't
look quite as good but is a lot more robust to a lot of copy&pasting
out in the web.

However, i would be very glad about anybody who finds the
silver-bullet to kill that werewolf :)

^ manveru


More information about the Ramaze-general mailing list