Last active
December 11, 2020 18:33
-
-
Save ayrton/f2916a37bf9dbd985437d7c1799fe6f6 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class ApplicationController < ActionController::Base | |
include EtagWithLayout | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module EtagWithLayout | |
extend ActiveSupport::Concern | |
include ActionController::ConditionalGet | |
included { etag { layout_etag if request.format.html? } } | |
private | |
def layout_etag | |
layout_name = determine_layout_name | |
if layout_name | |
ActionView::Digestor.digest name: layout_name, | |
format: nil, | |
finder: lookup_context | |
end | |
end | |
def determine_layout_name | |
current_layout = _layout lookup_context, %i[html] | |
case current_layout | |
when ActionView::Template | |
current_layout.virtual_path | |
when String | |
"layouts/#{current_layout}" | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment