【问题标题】:Rails render head vs. statusRails 渲染头与状态
【发布时间】:2023-03-29 08:15:01
【问题描述】:

Rails 中的render head :okrender status :ok 有什么区别?它们都作为标题返回对吗?

【问题讨论】:

    标签: ruby-on-rails render http-status-codes


    【解决方案1】:

    真的没有区别。 Rails doc 这么说head

    head 方法可用于将仅包含标头的响应发送到 浏览器。 head 方法接受一个数字或符号(见参考 table) 代表一个 HTTP 状态码

    head :ok 将渲染设置为仅返回状态为 200 的标头。

    它只是render nothing: true, status: :ok 的简写。

    当您没有为动作定义模板时,Rails 5 默认也会执行head :no_content

    【讨论】:

    • 所以render status :ok 更加通用,因为它也可以用作选项对吗?
    • 我想说的更详细。
    猜你喜欢
    • 2014-03-20
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-04-22
    • 2014-10-21
    • 1970-01-01
    • 2019-10-30
    相关资源
    最近更新 更多