在我当前的项目中,在为 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. Theheaders
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 toresponse.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/