我看到很多这样的例子:
def show
@article = Article.find(params[:id])
fresh_when(@article)
end
然而,该页面还包含有关登录用户的信息(如顶部导航)。用户可以:
... 哎呀,用户将看到有关用户 A 的数据,而不是用户 B,因为文章没有被修改。
如何在哈希(etag)中包含当前用户 ID?或者,是否有其他解决方案可以避免上述问题?
最佳答案
也许您可以将 current_user id 添加到所有 Controller 的 etag 中。
class ApplicationController < ActionController::Base
etag { current_user.try :id }
end
通过这种方式,您可以解决登录用户获取的内容可能与非登录用户不同的问题。
关于ruby-on-rails - Rails fresh_when 应该在 etag 中包含当前用户 ID,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59032877/