# Flash\[\] and Rails 2.0

**URL:** <https://www.ruby-forum.com/t/flash-and-rails-2-0/124184>\
**Category:** Rails\
**Created:** [December 26, 2007, 7:29am UTC](https://www.ruby-forum.com/t/flash-and-rails-2-0/124184 "2007-12-26T07:29:03Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![sharkie](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/58f4c7/32.png) [@sharkie](https://www.ruby-forum.com/u/sharkie)\
**Post date:** [December 26, 2007, 7:29am UTC](https://www.ruby-forum.com/t/flash-and-rails-2-0/124184/1 "2007-12-26T07:29:03Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![sharkie](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/58f4c7/32.png) [@sharkie](https://www.ruby-forum.com/u/sharkie)\
**Post date:** [December 26, 2007, 7:51am UTC](https://www.ruby-forum.com/t/flash-and-rails-2-0/124184/2 "2007-12-26T07:51:35Z")

</div>

Seems to work for me.

On Dec 26, 2007 4:59 PM, Sharkie L.  
[removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
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/](http://www.ruby-forum.com/).
> 
> >

–  
Ryan B.

> **[frozenplague.net](http://www.frozenplague.net)**
>
> This domain may be for sale!

Feel free to add me to MSN and/or GTalk as this email.

---

<div class="post-metadata">

**Author:** ![sharkie](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/58f4c7/32.png) [@sharkie](https://www.ruby-forum.com/u/sharkie)\
**Post date:** [December 26, 2007, 12:58pm UTC](https://www.ruby-forum.com/t/flash-and-rails-2-0/124184/3 "2007-12-26T12:58:42Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![sharkie](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/58f4c7/32.png) [@sharkie](https://www.ruby-forum.com/u/sharkie)\
**Post date:** [December 26, 2007, 3:49pm UTC](https://www.ruby-forum.com/t/flash-and-rails-2-0/124184/4 "2007-12-26T15:49:55Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![sharkie](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/58f4c7/32.png) [@sharkie](https://www.ruby-forum.com/u/sharkie)\
**Post date:** [December 29, 2007, 5:39am UTC](https://www.ruby-forum.com/t/flash-and-rails-2-0/124184/5 "2007-12-29T05:39:56Z")

</div>

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-

---

<div class="post-metadata">

**Author:** ![sharkie](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/58f4c7/32.png) [@sharkie](https://www.ruby-forum.com/u/sharkie)\
**Post date:** [December 27, 2007, 12:33am UTC](https://www.ruby-forum.com/t/flash-and-rails-2-0/124184/6 "2007-12-27T00:33:45Z")

</div>

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