Fix digesting non-HTML templates with non-unique logical names #25411
Conversation
…a format other than the first default
…view paths correctly
…n-default (html) template
…ates for other formats
matthewd
added a commit
that referenced
this pull request
Jun 16, 2016
Fix digesting non-HTML templates with non-unique logical names
5-0-stable: 8c9204d |
Thank you! |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
This fixes a pathological-sounding-but-it-happened-to-us scenario that caused incorrect template digests for
*/*
requests that render non-HTML (JSON, in our case) templates. The scene looks something like this:append_view_path(Rails.root.join("app/views/api"))
app/views
, but for different formats:app/views/api/todos/_todo.json.jbuilder
andapp/views/todos/_todo.html.erb
, both "logically" known astodos/todo
. Both of these partials havecache
fragments.schedules#show
) with a corresponding JSON template (show.json.jbuilder
) that in turn renders a collection of partials:json.todos @todos, partial: 'todos/todo', as: :todo
.fetch
requests to this action that doesn't set anAccept
header so it defaults to*/*
.The JSON response is correctly returned, but the template digest it uses for caching is computed using the HTML templates. Altering
_todo.json.jbuilder
does not invalidate its cache, but altering_todo.html.erb
does.We worked around the issue by adding an
Accept: application/json
header. Adding a.json
format to the URL would have worked around it too.Here are the new tests failing without the changes to
ActionView::Digestor
:All green with the changes.
/cc @jeremy @matthewd