url_for([:edit, @post])
is working and generating /comments/123/edit
. Now I need to add a query parameter, so that instead of
/comments/123/edit
it is
/comments/123/edit?qp=asdf
I tried url_for([:edit, @post], :qp => "asdf")
but no go.
Yes, that's what you should be doing. encodeURIComponent is the correct way to encode a text value for putting in part of a query string. but when it is decoded at the server, the parameters of url are interpreted as seperate parameters and not as part of the single url parameter.
To access an individual known param passed in the query string, you can use request. args. get('param') . This is the "right" way to do it, as far as I know.
url_for in Flask is used for creating a URL to prevent the overhead of having to change URLs throughout an application (including in templates). Without url_for , if there is a change in the root URL of your app then you have to change it in every page where the link is present.
When the GET request method is used, if a client uses the HTTP protocol on a web server to request a certain resource, the client sends the server certain GET parameters through the requested URL. These parameters are pairs of names and their corresponding values, so-called name-value pairs.
Use named routes.
edit_post_path(@post, :qp => "asdf")
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With