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.
Joshua M. (Guest)
on 2009-04-21 21: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
Frederick C. (Guest)
on 2009-04-21 22:12
(Received via mailing list)
On Apr 21, 6:56 pm, Joshua M. <removed_email_address@domain.invalid>
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
Joshua M. (Guest)
on 2009-04-21 22:13
Frederick C. wrote:
> On Apr 21, 6:56�pm, Joshua M. <removed_email_address@domain.invalid>
> 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?
Frederick C. (Guest)
on 2009-04-21 23:23
(Received via mailing list)
On Apr 21, 7:13 pm, Joshua M. <removed_email_address@domain.invalid>
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
Joshua M. (Guest)
on 2009-04-21 23: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.