url_for does not overwrite host
Posted by lori, Thu Jan 15 09:09:00 UTC 2009
I was trying to do something elegant today, as I was patching a release, so that our new subdomain model would work seemlessly on the mobile version of our site. So, if people come in on the "wrong" subdomain, I want to redirect them to the "right" subdomain.
It seemed like url_for was the answer, using :overwrite_params:
new_url = url_for( :overwrite_params => { :host => host_with_correct_subdomain } )
Seems like that shoulda worked. Unfortunately, it's basically a no-op on the url, so I had to resort to a bit of regular expression goo:
new_url.gsub!(/#{request.host}/, host_with_correct_subdomain)
Not really elegant I suppose, but it works.



