ccocchi / rabl-rails

Rails 4.2+ templating system with JSON, XML and Plist support.
MIT License
209 stars 51 forks source link

Prevent child partial template usage from polluting original template data #21

Closed johnbintz closed 11 years ago

johnbintz commented 11 years ago

When using a partial template from a child using this syntax:

child :object, :partial => 'child/template'

The orignal compiled template is polluted with the _data attribute from the first call to child. This prevents the template from being reused as the now stored on template _data method may not be accessible on other objects, causing method not found exceptions. This small change only adds the _data attribute to the copy of the template being used for rendering, preventing the template from becoming corrupted for reuse.

ccocchi commented 11 years ago

@johnbintz Nice catch :+1:

I prefered to use a dup on cache templates for 2 reasons : it avoids to create useless hashes if template caching is not used. And merge! (or any in place methods) can be used elsewhere in the source code (like you miss the one in extends) so this way we are sure that cached templates are never modified.

Thank you for the PR !

johnbintz commented 11 years ago

You're welcome! :)