0

我有一个带有 Article 模型的 Rails3 应用程序。

管理员登录后,只需转到 article/show 方法即可查看“未授权”的文章:

if !@article.is_authorized and !user_signed_in?
  raise ActionController::RoutingError.new('Not Found')
end

我想从授权的那一刻起缓存文章。在管理员审查它们时,如何防止它们被缓存?

如何在操作中放置如下代码?

if @article.is_authorized
  cache_action
  or cache_fragment
  or whatever
4

1 回答 1

0

如文档中所述,您可以传递一个 Proc:

caches_action :foo, if: lambda { your_condition_here }
于 2012-10-02T18:22:06.490 回答