Skip to content

Instantly share code, notes, and snippets.

Last active May 31, 2016
What would you like to do?
One way to make Rails consider the layout in an etag.
# By default, changes to the layout temnplate won't cause a Rails etag
# to change. I suppose this is to facilitate Turbolinks. Sometimes you
# might want to change an etag in response to changes in the layout -
# this is particularly true when working in development mode. This is
# one way to do it, there are probably other (read: likely better) ways
# to do this too.
class FooController < ApplicationController
# There's probably some API method to get the name of the layout
# rather than hard-coding it like I did here, but I'm too lazy to
# look it up right now.
etag {
ActionView::Digestor.digest(name: "layouts/application.html.erb", finder: view_context.lookup_context)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment