fresh_whenとrender

def index
  @foo = Foo.find(params[:id])
  render "bar"
end

こんな感じのやつに fresh_when を入れて

def index
  @foo = Foo.find(params[:id])
  fresh_when(@foo)
  render "bar"
end

とかやると、キャッシュが効いたときに AbstractController::DoubleRenderError になってしまう。

ソースみると fresh_whenの中 head :not_modified してヘッダを送ってしまっているのでこうなるらしい。

def index
  @foo = Foo.find(params[:id])
  fresh_when(@foo)
  render "bar" unless request.fresh?(response)
end

として直したけど、Rails Guide読むと

If you don't have any special response processing and are using the default rendering mechanism (i.e. you're not using respond_to or calling render yourself) then you've got an easy helper in fresh_when:

とか書いてあって、自分で renderするときは

def index
  @foo = Foo.find(params[:id])
  render "bar" if stale?(@foo)
end

とやるのがいいみたい。turbolinkを疑ってすごく時間を潰してしまった。