0

I want to redirect the user to a named route but to a different subdomain. I thought that specifying the host as the last param to redirect_to would do it, but it just doesn't work. Here is the code I am using:

redirect_to(log_in_url(return_to: request.fullpath), host: "https://acme.lvh.me:3000/")

For some reason that doesn't work. Here is a scenario and what's happening:

  • I'm on https://oauth.lvh.me:3000/oauth/authorize
  • I use the redirect_to method specified above.
  • It redirects me to https://oauth.lvh.me:3000/log_in
  • It should instead have redirected me to https://acme.lvh.me:3000/log_in

What am I doing wrong please?

Robert Audi
  • 8,019
  • 9
  • 45
  • 67

2 Answers2

0

I found the problem myself. First of all the host: "https://acme.lvh.me:3000/ should be host: acme.lvh.me instead. Second of all, the option should be passed to the log_in_url method not to the return_to method!

Robert Audi
  • 8,019
  • 9
  • 45
  • 67
0

I think it should be simple. Try with something like this:

redirect_to request.url.sub('oauth', 'acme')
Aleks
  • 4,866
  • 3
  • 38
  • 69
  • I found the solution to my problem, look at my answer. By the way, `request.url` is deprecated, use `"#{request.protocol}#{request.host_with_port}#{request.fullpath}"` instead for a similar output. Source: http://stackoverflow.com/questions/2165665/how-do-i-get-the-current-url-in-ruby-on-rails – Robert Audi Mar 01 '13 at 14:37