문제

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/

도움이 되었습니까?

해결책

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}"

다른 팁

You can do it like this:

redirect_to "http://#{domain}#{path}"
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top