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

标签 ruby-on-rails ruby http redirect

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

相关文章:

ruby-on-rails - Rails3 种子数据嵌套属性

ruby-on-rails - 灵活点系统的 Rails 模型

ruby - 样式/条件分配 : Use the return of the conditional for variable assignment and comparison

java - 从 Android 应用程序到 GoDaddy 服务器的 HTTP 请求间歇性超时

http - 发生授权错误时的 CORS 和预检 (OPTIONS) 响应代码

ruby-on-rails - `require '有什么区别rails '` and ` require 'rails/all'`?

ruby - 从数组中删除项目需要多次传递才能将它们全部删除

mysql - 尝试在 Ruby 1.9.3、Rails 3.2.7、mstwjs Noel Rappin 教程应用程序中加载 gem 'mysql2' 时出错

java - Camel代理动态url参数设置

ruby-on-rails - 如何将 Capybara 功能测试标记为待定?