I can't work this out.
url = "www.mysite.com/?param1=abc"
redirect_to(url, :param2 => 'xyz')
### Should this go to - www.mysite.com/?param1=abc¶m2=xyz
Or am I missing something? It doesn't seem to work?
I can't work this out.
url = "www.mysite.com/?param1=abc"
redirect_to(url, :param2 => 'xyz')
### Should this go to - www.mysite.com/?param1=abc¶m2=xyz
Or am I missing something? It doesn't seem to work?
it won't know about the old params unless you merge them in and send them on.
url = "www.mysite.com/?param1=abc"
p = params.merge({:param2 => 'xyz'})
redirect_to(url, p)
redirect_to
is not a Ruby function but is commonly used in Ruby on Rails. You can find its documentation with a lot of working examples here.
If you want to open a website within plain Ruby, use the 'open-uri' class. You can find its documentation here.
I hope this helps understanding why redirect_to
doesn't work in plain Ruby and might help using it with and without Rails.
From the documentation:
You're passing a String as the first argument, so it's using the 3rd option. Your second parameter is interpreted as the value for the
response_status
parameter.So, if your redirect is an internal one (to the same app), you don't need to specify the scheme and hostname. Just use
If it's an external URL, build the complete URL before redirecting: