Question

I'm redirecting in rails using a string like so:

path = "/blerg/blergs/blergs/blergs"

domain = "www.google.com"

So in the controller I'm redirect like this:

redirect_to path, :status => :found, :host => domain

The problem is the domain isn't changing, it's staying the same as the app's domain. How do redirect with the host param while using a string as the path?

The reason I'm doing this to avoid this security bug, the path has some params in it too: http://brakemanscanner.org/docs/warning_types/redirect/

Was it helpful?

Solution

As you can see here, when you use string paths, rails use request's domain.

one way to tell rails that url you are passing is in another domain, is to set the protocol:

     url = "http://#{another_domain_url}"
     redirect_to url

If you want to use a hash, you can move path to :host key (not tested):

     redirect_to :status => :found, :host => "#{domain}#{path}"

OTHER TIPS

You can do it like this:

redirect_to "http://#{domain}#{path}"
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top