Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cover all aspects of url_for in the guides #1109

Open
kraih opened this issue Jul 22, 2017 · 5 comments
Open

Cover all aspects of url_for in the guides #1109

kraih opened this issue Jul 22, 2017 · 5 comments

Comments

@kraih
Copy link
Member

kraih commented Jul 22, 2017

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.

@lindleyw
Copy link
Contributor

Perhaps at least note that:

url_for when called without params returns current url

stackoverflow

@kraih
Copy link
Member Author

kraih commented Aug 1, 2017

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

@kraih
Copy link
Member Author

kraih commented Dec 2, 2017

For starters i've added some more examples to the reference docs. But something in the guides would be nice. 0c513be

@jberger
Copy link
Member

jberger commented Dec 13, 2017

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

@mavit
Copy link

mavit commented Aug 23, 2022

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')});

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants