Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to write a redirect that uses relative_url_root if defined?

I'm currently using Ruby on Rails 3.2.8 and have this redirect in config/routes.rb:

root :to => redirect("/home/index.html")

which works fine for redirecting http://localhost:3000/ to http://localhost:3000/home/index.html in development. But in my test environment, I'm using a proxy and a subpath, setting relative_url_root in config/environments/test.rb like this:

config.action_controller.relative_url_root = '/testpath'

So I would expect a redirect from http://testdomain.com/testpath to http://testdomain.com/testpath/home/index.html but instead it redirects to http://testdomain.com/home/index.html.

How can I change my redirect statement to use relative_url_root in case it is set?

like image 936
Kevin Schmidt Avatar asked Dec 04 '12 00:12

Kevin Schmidt


1 Answers

I don't think that the method is deprecated, but it does seem to be broken. You should be able to work around the issue with something like this:

root :to => redirect("#{ Rails.application.config.action_controller.relative_url_root }/home/index.html")

It might be worth pointing out that this bug is not reproducible on my machine (I am using thin), the code you posed works as intended.

like image 191
Brad Werth Avatar answered Oct 31 '22 20:10

Brad Werth