Allow any key in Renderer environment hash #26786

Merged
merged 1 commit into from Oct 15, 2016

Projects

None yet

5 participants

@codeodor
Contributor
codeodor commented Oct 13, 2016 edited

When rendering arbitrary templates, it would be helpful to not overwrite env keys with nil if they don't match any found in the RACK_KEY_TRANSLATION hash.

Is there any interest in this?

@rails-bot

r? @eileencodes

(@rails-bot has picked a reviewer for you, use r? to override)

@rafaelfranca
Member

Depends, could you show the use case for this? Right now I don't see why people would want this.

@codeodor
Contributor
codeodor commented Oct 13, 2016 edited

In my case, I want to pass a key for Warden so that my templates will not throw errors.

But more generally, I was rather surprised that it converted my keys to nil instead of just passing them through. I would imagine there are an infinite number of ways that view templates might rely on the environment outside of those predefined keys in the RACK_KEY_TRANSLATION hash.

@codeodor
Contributor
@codeodor
Contributor

More specifically, if I do something like this:

warden_manager = "set up warden"
SomeController.renderer.new(warden: warden_manager).render

Then in the template, if we check request.env['warden'] it is currently nil. If instead we check request.env[nil] it will be "set up warden".

This pull request fixes it so that the renderer will not produce the extra nil key, and to where request.env['warden'] will equal "set up warden"

@rafaelfranca

Thank you for the explanation. Could you add a test case and a CHANGELOG entry?

@codeodor codeodor Allow any key in Renderer environment hash
When rendering arbitrary templates, it is helpful to not overwrite `env` keys with nil if they don't match any found in the `RACK_KEY_TRANSLATION`

This allows the developer to set the environment to exactly what is needed for rendering.
6fccd7b
@codeodor
Contributor

Thanks @rafaelfranca, and done!

@eileencodes eileencodes merged commit 28ce091 into rails:master Oct 15, 2016

2 checks passed

codeclimate Code Climate didn't find any new or fixed issues.
Details
continuous-integration/travis-ci/pr The Travis CI build passed
Details
@eileencodes
Member

Thanks @codeodor! 😄

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment