gpt4 book ai didi

ruby-on-rails - 如果已定义,如何编写使用 relative_url_root 的重定向?

转载 作者:数据小太阳 更新时间:2023-10-29 07:15:21 26 4
gpt4 key购买 nike

我目前正在使用 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,我如何更改我的重定向语句以使用它?

最佳答案

我不认为该方法已被弃用,但它 does seem to be broken .您应该能够通过以下方式解决此问题:

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

可能值得指出的是,此错误无法在我的机器上重现(我使用的是 thin),您提供的代码按预期工作。

关于ruby-on-rails - 如果已定义,如何编写使用 relative_url_root 的重定向?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13694165/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com