Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow any key in Renderer environment hash #26786

Merged
merged 1 commit into from Oct 15, 2016
Merged

Conversation

@codeodor
Copy link
Contributor

@codeodor codeodor commented Oct 13, 2016

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
Copy link

@rails-bot rails-bot commented Oct 13, 2016

r? @eileencodes

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

@rafaelfranca
Copy link
Member

@rafaelfranca rafaelfranca commented Oct 13, 2016

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

@codeodor
Copy link
Contributor Author

@codeodor codeodor commented Oct 13, 2016

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
Copy link
Contributor Author

@codeodor codeodor commented Oct 13, 2016

@codeodor
Copy link
Contributor Author

@codeodor codeodor commented Oct 14, 2016

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"

Copy link
Member

@rafaelfranca rafaelfranca left a comment

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

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.
@codeodor codeodor force-pushed the codeodor:patch-1 branch to 6fccd7b Oct 15, 2016
@codeodor
Copy link
Contributor Author

@codeodor codeodor commented Oct 15, 2016

Thanks @rafaelfranca, and done!

@eileencodes eileencodes merged commit 28ce091 into rails:master Oct 15, 2016
2 checks passed
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
Copy link
Member

@eileencodes eileencodes commented Oct 15, 2016

Thanks @codeodor! 😄

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked issues

Successfully merging this pull request may close these issues.

None yet

5 participants