Skip to content

Instantly share code, notes, and snippets.

@norman
Last active May 31, 2016 11:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save norman/b769b528e003da569968a9b2c4cf889c to your computer and use it in GitHub Desktop.
Save norman/b769b528e003da569968a9b2c4cf889c to your computer and use it in GitHub Desktop.
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)
}
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment