Flash[] and Rails 2.0

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.

Seems to work for me.

On Dec 26, 2007 4:59 PM, Sharkie L.
[email protected]
wrote:

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.

Posted via http://www.ruby-forum.com/.


Ryan B.
http://www.frozenplague.net
Feel free to add me to MSN and/or GTalk as this email.

On 26 Dec 2007, at 06:29, Sharkie L. wrote:

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

Frederick C. wrote:

On 26 Dec 2007, at 06:29, Sharkie L. wrote:

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-

When assigning flash, use flash[:notice] instead of @flash[:notice]. As
Fred
said, that was deprecated in Rails 2.0

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs