Created
January 5, 2011 18:51
-
-
Save bdmac/766778 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
# The problem below is that the JS responses were not being cached properly | |
# but the HTML responses were fine. | |
caches_action :show, :layout => false, :expires_in => 24.hours | |
def show | |
respond_to do |wants| | |
wants.html | |
wants.js { | |
# What... the... fuck... After tracing why the JS responses to this action | |
# were not being action cached through rails' internals, this is what I | |
# determined needed to be done. For whatever reason, content_for_layout | |
# in ActionController::Caching::Actions expects response.layout and | |
# @cached_content_for_layout to be set when :layout => false is set. | |
# They were set just fine for HTML responses but JS responses did not | |
# have them set?!?! Manually setting them here allows the JS responses to | |
# get cached... | |
response.layout = 'layouts/application' # Why? | |
cached_content = render :partial => 'category_item' | |
response.template.instance_variable_set('@cached_content_for_layout', cached_content) # WTF? | |
} | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment