# You have a nil object when you didn't expect it!

**URL:** <https://www.ruby-forum.com/t/you-have-a-nil-object-when-you-didnt-expect-it/157318>\
**Category:** Rails\
**Created:** [January 9, 2009, 11:06am UTC](https://www.ruby-forum.com/t/you-have-a-nil-object-when-you-didnt-expect-it/157318 "2009-01-09T11:06:55Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![giga](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/b9bd4f/32.png) [@giga](https://www.ruby-forum.com/u/giga)\
**Post date:** [January 9, 2009, 11:06am UTC](https://www.ruby-forum.com/t/you-have-a-nil-object-when-you-didnt-expect-it/157318/1 "2009-01-09T11:06:55Z")

</div>

\<% if @flash[:error] %\>

\<%= @flash[:error] %\>
  
\<% end %\>  
\<% if @flash[:warning] %\>  

\<%= @flash[:warning] %\>
  
\<% end %\>  
\<% if @flash[:notice] %\>  

\<%= @flash[:notice] %\>
  
\<% end %\>
* * *

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.[]

How I must do it?

---

<div class="post-metadata">

**Author:** ![giga](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/b9bd4f/32.png) [@giga](https://www.ruby-forum.com/u/giga)\
**Post date:** [January 9, 2009, 11:24am UTC](https://www.ruby-forum.com/t/you-have-a-nil-object-when-you-didnt-expect-it/157318/2 "2009-01-09T11:24:14Z")

</div>

Hi,

Did you see any line number in the error?  
It would be helpful if you gould give the whole trace rather than just  
the  
error message

NAYAK

On Fri, Jan 9, 2009 at 3:36 PM, Gi Ga  
[removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)wrote:

> >

–

- NAYAK

---

<div class="post-metadata">

**Author:** ![giga](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/b9bd4f/32.png) [@giga](https://www.ruby-forum.com/u/giga)\
**Post date:** [January 9, 2009, 11:28am UTC](https://www.ruby-forum.com/t/you-have-a-nil-object-when-you-didnt-expect-it/157318/3 "2009-01-09T11:28:23Z")

</div>

> How I must do it?  
> could it be, it’s “flash[:notice]” without the @.

if not, tell us where your error occurred (which line). then show us  
the code calling it (controller/action).

---

<div class="post-metadata">

**Author:** ![giga](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/b9bd4f/32.png) [@giga](https://www.ruby-forum.com/u/giga)\
**Post date:** [January 9, 2009, 12:00pm UTC](https://www.ruby-forum.com/t/you-have-a-nil-object-when-you-didnt-expect-it/157318/4 "2009-01-09T12:00:05Z")

</div>

MaD wrote:

> could it be, it’s “flash[:notice]” without the @.

Thanks, now it works.
