How to write a redirect that uses relative_url_root, if defined?

I am currently using Ruby on Rails 3.2.8 and redirecting it to config / routes.rb :

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

which is great for redirecting http: // localhost: 3000 / to http: // localhost: 3000 / home / index.html in development. But in my test environment, I use a proxy and subpath, setting relative_url_root in config / environment / test.rb as follows:

 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 the redirection operator to use relative_url_root if it is set?

+4
source share
2 answers

I do not think the method is deprecated, but it seems to be broken . You should be able to get around the problem with something like this:

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

It may be worth noting that this error does not reproduce on my machine (I use a thin one), the code that you created works as intended.

+6
source

The relative_url_root method seems to be deprecated. See This SO Post for Rails 3 Solution: Changing the Base URL for Rails 3 Development

0
source

All Articles