mojo icon indicating copy to clipboard operation
mojo copied to clipboard

Cover all aspects of url_for in the guides

Open kraih opened this issue 8 years ago • 5 comments

Using url_for with named routes is pretty well covered.

# "/myapp/index.html?foo=bar" if application is deployed under "/myapp"
$c->url_for('/index.html')->query(foo => 'bar');

But how it can make relative paths absolute, or how the returned Mojo::URL object can be modified is not covered very well yet.

kraih avatar Jul 22 '17 22:07 kraih

Perhaps at least note that:

url_for when called without params returns current url

stackoverflow

lindleyw avatar Jul 23 '17 15:07 lindleyw

I suppose this could also cover why $c->req->url is relative and $c->req->url->to_abs absolute.

kraih avatar Aug 01 '17 12:08 kraih

For starters i've added some more examples to the reference docs. But something in the guides would be nice. https://github.com/kraih/mojo/commit/0c513be6ef423e5cb4ab4a16448d1451e01d39ac

kraih avatar Dec 02 '17 12:12 kraih

This should also clarify some aspects of links generated relative to the base path. See for example the confusion here https://irclog.perlgeek.de/mojo/2017-12-13#i_15572052 about some of the tag helpers where %= stylesheet '/foo.css' becomes /path/to/foo.css

jberger avatar Dec 13 '17 14:12 jberger

I was surprised to discover the following behaviour, that placeholder values passed to url_for are expected to already be percent encoded. I did not see that mentioned anywhere in the documentation.

# /example/foo%3Fbar
$self->url_for('example', {'placeholder' => 'foo?bar'}); # Seems to work, but...

# /example/foo%C2%BAr
$self->url_for('example', {'placeholder' => 'foo%bar'}); # Bad

# /example/foo%3Fbar
$self->url_for('example', {'placeholder' => url_escape('foo?bar'}));

# /example/foo%25bar
$self->url_for('example', {'placeholder' => url_escape('foo%bar')});

mavit avatar Aug 23 '22 11:08 mavit