I have nill object when i didn't expect it


#1

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 %>


#2

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).