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

don't create a local variable with the name of the partial when no :local or :object option was passed #7687

Closed
jfirebaugh opened this issue Sep 18, 2012 · 2 comments

Comments

@jfirebaugh
Copy link
Contributor

From this stack overflow question.

Suppose I have a partial _flash.html.erb for rendering the flash in a consistent way. The natural thing to do would be to assume I can call ActionView::Base#flash from within this partial to retrieve the flash, and render the partial with render partial: "flash". But in fact, this doesn't work. Even though I haven't passed object: flash or locals: {flash: flash} in the call to render partial, PartialRenderer oh-so-helpfully defines a flash local variable, whose value is nil, shadowing ActionView::Base#flash. My alternatives are to rename the partial or pass a value for the flash local explicitly using one of those more verbose call to render.

I suggest that if no object option or local with the same name as the partial was passed to the render call, that PartialRenderer not define a local variable of the same name as the partial. This would change the behavior for anyone who is relying on the current behavior to get a nil value for the local when they don't pass an explicit value, but that seems like an unlikely case and easily fixed by passing nil explicitly, and it would be much more useful to do things like call ActionView::Base#flash from within a _flash.html.erb partial.

I'm happy to create a pull request if others agree.

@steveklabnik
Copy link
Member

We don't accept feature requests on the Issues tracker. Please either submit a pull request or ask for feedback on rails-core. Thanks.

@frodsan
Copy link
Contributor

frodsan commented Sep 18, 2012

Also, reading CONTRIBUTING guide is a good start before posting an issue :)

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

No branches or pull requests

3 participants