>From this stack overflow
>question<http://stackoverflow.com/questions/3111844/flash-messages-in-partials-rails-3/12482879>
.
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 withrender partial: "flash". But in fact, this doesn't
work. Even though I haven't passed object: flash orlocals: {flash: flash} in
the call to render partial, PartialRenderer oh-so-helpfully defines a
flashlocal
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, thatPartialRenderer *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.
--
You received this message because you are subscribed to the Google Groups "Ruby
on Rails: Core" group.
To view this discussion on the web visit
https://groups.google.com/d/msg/rubyonrails-core/-/sHiSiBDAdOkJ.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/rubyonrails-core?hl=en.