For some very odd reasons, flash[] evaluates to nil inside a partial,
but not elsewhere.
This was not the case with previous rails.
I have a controller called Stories, so in /layouts/stories I can access
flash[], but if I render :partial => ‘flash’ inside the layout, and
_flash contains flash[], it would evaluate to nil and crash my app.
Is there something that works differently with Rail 2.0? it was OK
before the update.
I can use flash[] in helpers and controllers with no problems.
Is there something that works differently with Rail 2.0? it was OK
before the update.
Prior to rails 2.0, @flash contained the same thing as flash (but was
deprecated).
When you do render :partial => ‘flash’, it picks up on the @flash
variable (which is still there but nil) and assigns that to flash in
your partial.
So you can get round this by:
-renaming your partial
-using flash()[:foo] instead of flash[:foo] (which will tell ruby to
do the method call rather than use the local variable
Is there something that works differently with Rail 2.0? it was OK
before the update.
Prior to rails 2.0, @flash contained the same thing as flash (but was
deprecated).
When you do render :partial => ‘flash’, it picks up on the @flash
variable (which is still there but nil) and assigns that to flash in
your partial.
So you can get round this by:
-renaming your partial
-using flash()[:foo] instead of flash[:foo] (which will tell ruby to
do the method call rather than use the local variable
Fred
Thank you. This had be worried that something was seriously wrong with
my configuration. Is this to be changed sometime soon? In that it will
not pick up @flash?
I just ran into this problem too. Thanks for the advice Frederick, as
that was the issue. I named my partial “flash”, and I forget that
partials automatically get a local variable with the same name.
For example, if you create a partial named “product”, and then use
<%= render :partial => “product”, :collection => @products %>
The partial will have a local variable “product” that represents the
product for each one. Rails will happily override the flash hash with
the partial name (and set it to nil).
On Dec 26, 6:49 am, Sharkie L. <rails-mailing-l…@andreas-