# I have nill object when i didn't expect it

**URL:** <https://www.ruby-forum.com/t/i-have-nill-object-when-i-didnt-expect-it/163853>\
**Category:** Rails\
**Created:** [March 25, 2009, 3:28pm UTC](https://www.ruby-forum.com/t/i-have-nill-object-when-i-didnt-expect-it/163853 "2009-03-25T15:28:43Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![eswarrior](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/e/df705f/32.png) [@eswarrior](https://www.ruby-forum.com/u/eswarrior)\
**Post date:** [March 25, 2009, 3:28pm UTC](https://www.ruby-forum.com/t/i-have-nill-object-when-i-didnt-expect-it/163853/1 "2009-03-25T15:28:43Z")

</div>

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

I made a simple pages admin. When i tried to automate the permalink by  
adjusting the title i got tis error the model is enclosed in the  
attachment.  
whatever is commented on the page i do not wish to have on my page  
anymore, but i did not wan’t to delete them either,

# New page

\<% form\_for(@page) do |f| %\>  
\<%= f.error\_messages %\>

\<%# f.label :id %\>  
 \<%# f.text\_field :id %\>

\<%= f.label :title %\>  
 \<%= f.text\_field :title %\>

\<%# f.label :permalink %\>  
 \<%# f.text\_field :permalink %\>

\<%= f.label :body %\>  
 \<%= f.text\_area :body %\>

\<%= f.label :created\_at %\>  
 \<%= f.datetime\_select :created\_at %\>

\<%= f.label :updated\_at %\>  
 \<%= f.datetime\_select :updated\_at %\>

\<%= f.submit "Create" %\>

\<% end %\>

\<%= link\_to ‘Back’, pages\_path %\>

---

<div class="post-metadata">

**Author:** ![eswarrior](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/e/df705f/32.png) [@eswarrior](https://www.ruby-forum.com/u/eswarrior)\
**Post date:** [March 26, 2009, 6:03pm UTC](https://www.ruby-forum.com/t/i-have-nill-object-when-i-didnt-expect-it/163853/2 "2009-03-26T18:03:00Z")

</div>

Eelke Wolters wrote:

> 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.[]=
> 
> I made a simple pages admin. When i tried to automate the permalink by  
> adjusting the title i got tis error the model is enclosed in the  
> attachment.  
> whatever is commented on the page i do not wish to have on my page  
> anymore, but i did not wan’t to delete them either,

You posed the wrong code. This error is not happening in your view code  
it’s happening in your controller.

You need to examine the code used to find @page. My guess is that it  
trying to do something like:

@page = Page.find(x)

Where x used to be the id of the record to find, but it now a string  
containing your permalink. That’s is purely a guess since you didn’t  
post the controller code that is throwing this exception.

So basically Rails is telling you that you were probably expecting  
form\_for(@page) to be a form for an ActiveRecord::Base instance, but you  
are actually creating a form for nil form\_for(nil).
