# Newbie Question - Nil Error in ActiveController

**URL:** <https://www.ruby-forum.com/t/newbie-question-nil-error-in-activecontroller/125810>\
**Category:** Rails\
**Created:** [January 12, 2008, 7:36am UTC](https://www.ruby-forum.com/t/newbie-question-nil-error-in-activecontroller/125810 "2008-01-12T07:36:28Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![deadSkip](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/839c29/32.png) [@deadSkip](https://www.ruby-forum.com/u/deadSkip)\
**Post date:** [January 12, 2008, 7:36am UTC](https://www.ruby-forum.com/t/newbie-question-nil-error-in-activecontroller/125810/1 "2008-01-12T07:36:28Z")

</div>

Hi everyone, looking for some help with this error below. It seems  
that althought it finds the product\_line\_id attribute, the code  
doesn’t find the product\_line’s name attribute. I’ve already declared  
the has\_many: call\_driver relationship in the product\_line model, and  
the belongs\_to: product\_line relationship in the call\_driver model.

It also works in the console, oddly enough, but not in the view.

I know I’m missing something elemental here, but I haven’t the  
faintest clue what it is.

### 

NoMethodError in Admin#index

Showing admin/index.html.erb where line #13 raised:

You have a nil object when you didn’t expect it!  
The error occurred while evaluating nil.name  
Extracted source (around line #13):

10: \<% for driver in @driver %\>  
11:

  
12: \<%=h driver.name %\>  
13: \<%=h driver.product\_line.name %\>  
14: \<%= link\_to ‘Edit’, {:action =\> ‘driver\_edit’} %\>  
15: \<%= link\_to ‘Destroy’, {:action =\> ‘driver\_delete’,:id =\>  
driver.id} %\>  
16: 
### 

admin\_controller has this for the index action;

def index  
@driver = CallDriver.find(:all)

```
respond_to do |format|
  format.html # index.html.erb
  format.xml { render :xml => @driver }
end

```

end

---

<div class="post-metadata">

**Author:** ![deadSkip](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/839c29/32.png) [@deadSkip](https://www.ruby-forum.com/u/deadSkip)\
**Post date:** [January 12, 2008, 7:38am UTC](https://www.ruby-forum.com/t/newbie-question-nil-error-in-activecontroller/125810/2 "2008-01-12T07:38:48Z")

</div>

What’s interesting is that I’ve done almost entirely the same thing  
with another view, and it works;

###### View

\<% for driver in @drivers %\>

 \<%= driver.name %\> \<%= driver.product\_line.name %\> \<% end %\>
###### Controller

class ShowController \< ApplicationController  
def show\_drivers

# Find Call Drivers

@drivers =  
CallDriver.find(:all, :conditions =\> [  
‘product\_line\_id = :product\_line and  
sub\_product\_line\_id = :sub\_product\_line and  
platform\_id = :platform and  
consolidation\_id = :consolidation and  
segment\_id = :segment’,  
{:product\_line =\> params[:product\_line],  
:sub\_product\_line =\> params[:sub\_product\_line],  
:platform =\> params[:platform],  
:consolidation =\> params[:consolidation],  
:segment =\> params[:segment]}])  
respond\_to do |format|  
format.html  
format.xml { render :xml =\> @drivers }  
end  
end  
end

---

<div class="post-metadata">

**Author:** ![deadSkip](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/839c29/32.png) [@deadSkip](https://www.ruby-forum.com/u/deadSkip)\
**Post date:** [January 12, 2008, 7:40am UTC](https://www.ruby-forum.com/t/newbie-question-nil-error-in-activecontroller/125810/3 "2008-01-12T07:40:33Z")

</div>

Please disregard, I’ve discovered the problem. I’m an idiot and forgot  
that some of my data didn’t have a product\_line\_id set.
