gpt4 book ai didi

ruby-on-rails - redirect_to 自定义 http header

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

在我当前的项目中,在为 http 基本身份验证重定向时需要设置自定义 http header 变量。我可以为自定义 header 指示 redirect_to 吗?

谢谢。

最佳答案

Rails 允许您在重定向时添加自定义 header 。在 Rails guides 中进行了讨论.

10.2.1 Setting Custom Headers

If you want to set custom headers for a response then response.headers is the place to do it. The headers attribute is a hash which maps header names to their values, and Rails will set some of them automatically. If you want to add or change a header, just assign it to response.headers

所以你的操作代码最终会是这样的:

def some_action
# do_some_work

response.headers["your-key"] = "some value"
redirect_to url
end

关于ruby-on-rails - redirect_to 自定义 http header ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3036398/

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