gpt4 book ai didi

ruby-on-rails - Rails 条件获取(开发模式)仍然返回 "Not Modified"(`#fresh_when()` )

转载 作者:可可西里 更新时间:2023-11-01 15:28:41 25 4
gpt4 key购买 nike

为什么以下(在开发模式下)错误地返回“304 未修改”- 在开发模式下运行时,Rails 中不应默认禁用此类功能?

我的 Controller 看起来像这样:

class WidgetController < ApplicationController

def show
@widget = Widget.find(params[:id])
fresh_when(etag: etag_for(@widget), last_modified: @widget.updated_at)
end

private

def etag_for(*args)
args.flatten + [current_user, last_deploy]
end

def last_deploy
`git log --pretty=format:%H`.chomp
end

end

我不清楚为什么在我的 Rails 应用程序的 Development 模式下,这会返回“304 Not Modified” header ,我认为根据开发模式,不会启用此类功能?

我在本地使用瘦网络服务器,我认为这有点不寻常,否则这是一个没有特殊条件的典型应用程序,或者在 Rails 3.1.1

上运行的情况

最佳答案

所以答案比这更简单:

./config/environments/development.rb 中,我添加了以下行:

  config.middleware.delete(Rack::ConditionalGet)

我向 Rails 提交了这个“错误”以获得官方回应,可以找到该问题 here at their Github issue tracker .

关于ruby-on-rails - Rails 条件获取(开发模式)仍然返回 "Not Modified"(`#fresh_when()` ),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8040397/

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