如果定义了如何编写使用relative_url_root的重定向?

Kev*_*idt 5 ruby ruby-on-rails rails-routing

我目前正在使用Ruby on Rails 3.2.8并在config/routes.rb中进行此重定向:

root :to => redirect("/home/index.html")
Run Code Online (Sandbox Code Playgroud)

适用于在开发中将http:// localhost:3000 /重定向到http:// localhost:3000/home/index.html.但是在我的测试环境中,我正在使用代理和子路径,在config/environments/test.rb中设置relative_url_root,如下所示:

config.action_controller.relative_url_root = '/testpath'
Run Code Online (Sandbox Code Playgroud)

所以我希望从http://testdomain.com/testpath重定向到http://testdomain.com/testpath/home/index.html,而是重定向到http://testdomain.com/home/index.html.

如果设置了,我如何更改我的重定向语句以使用relative_url_root?

Bra*_*rth 6

我不认为该方法已被弃用,但似乎确实被打破了.您应该可以使用以下方法解决问题:

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

可能值得指出的是,这个bug在我的机器上是不可重现的(我使用的是瘦),你提出的代码按预期工作.