Forum: Ruby on Rails My flash is not accessible anymore!

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
Fc582698581884352e745d1d4c64699d?d=identicon&s=25 Joshua Muheim (josh)
on 2009-04-21 19:56
Hi all

For some reason I can't access my flash object anymore! When putting

<p style="color: green"><%= flash[:notice] %></p>

in my view, I get the following error:

You have a nil object when you didn't expect it!
You might have expected an instance of ActiveRecord::Base.
The error occurred while evaluating nil.[]

Extracted source (around line #1):

1: <%= flash[:notice] %>

What the heck is the problem here? I can't remember doing anything that
could have caused this..?

Thanks for help
Josh
81b61875e41eaa58887543635d556fca?d=identicon&s=25 Frederick Cheung (Guest)
on 2009-04-21 20:12
(Received via mailing list)
On Apr 21, 6:56 pm, Joshua Muheim <rails-mailing-l...@andreas-s.net>
wrote:

> Extracted source (around line #1):
>
> 1: <%= flash[:notice] %>
>
> What the heck is the problem here? I can't remember doing anything that
> could have caused this..?
>
is this in a partial or view called flash ?

Fred
Fc582698581884352e745d1d4c64699d?d=identicon&s=25 Joshua Muheim (josh)
on 2009-04-21 20:13
Frederick Cheung wrote:
> On Apr 21, 6:56�pm, Joshua Muheim <rails-mailing-l...@andreas-s.net>
> wrote:
>
>> Extracted source (around line #1):
>>
>> 1: <%= flash[:notice] %>
>>
>> What the heck is the problem here? I can't remember doing anything that
>> could have caused this..?
>>
> is this in a partial or view called flash ?
>
> Fred

yes, it is within layouts/_flash.html.erb

Is this a problem?
81b61875e41eaa58887543635d556fca?d=identicon&s=25 Frederick Cheung (Guest)
on 2009-04-21 21:23
(Received via mailing list)
On Apr 21, 7:13 pm, Joshua Muheim <rails-mailing-l...@andreas-s.net>
wrote:
>
> > is this in a partial or view called flash ?
>
> > Fred
>
> yes, it is within layouts/_flash.html.erb
>
> Is this a problem?

Yes. partials get a local variable named after them, in this case
flash, which is shadowing rails' flash

self.flash[:notice]

should work.

Fred
Fc582698581884352e745d1d4c64699d?d=identicon&s=25 Joshua Muheim (josh)
on 2009-04-21 21:25
> Yes. partials get a local variable named after them, in this case
> flash, which is shadowing rails' flash
>
> self.flash[:notice]
>
> should work.
>
> Fred

Wow, thanks a lot for this information. :-)
This topic is locked and can not be replied to.