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

时间:2012-12-04 00:22:48

标签: ruby-on-rails ruby rails-routing

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

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

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

config.action_controller.relative_url_root = '/testpath'

所以我希望从 http://testdomain.com/testpath 重定向到 http://testdomain.com/testpath/home/index.html 但是相反,它会重定向到 http://testdomain.com/home/index.html

我如何更改我的重定向语句以便在设置时使用relative_url_root?

2 个答案:

答案 0 :(得分:6)

我不认为该方法已被弃用,而是does seem to be broken。您应该可以通过以下方式解决问题:

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

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

答案 1 :(得分:0)

似乎已弃用relative_url_root方法。有关Rails 3解决方案,请参阅此SO帖子:Changing the base URL for Rails 3 development

相关问题