# Nil object error

**URL:** <https://www.ruby-forum.com/t/nil-object-error/124762>\
**Category:** Rails\
**Created:** [January 2, 2008, 10:42am UTC](https://www.ruby-forum.com/t/nil-object-error/124762 "2008-01-02T10:42:48Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Haris\_G](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/h/8edcca/32.png) [@Haris\_G](https://www.ruby-forum.com/u/Haris_G)\
**Post date:** [January 2, 2008, 10:42am UTC](https://www.ruby-forum.com/t/nil-object-error/124762/1 "2008-01-02T10:42:48Z")

</div>

Hello all,

Im getting a nil object error. here under are the details of my app. My  
index.rhtml file is

\<% @result.each do |res| %\>  
\<%= res.first\_name %\>  
  
  
\<%= res.register.language\_speak %\>  
  
  
  
  
  
\<% end %\>

My models are as follows

class Profile \< ActiveRecord::Base  
has\_many :friends, :foreign\_key =\> “user\_id”  
has\_one :register, :foreign\_key =\> “id”

def self.table\_name() “mhp\_profile” end  
end

class Friend \< ActiveRecord::Base  
belongs\_to :profile

def self.table\_name() “mhp\_friends” end  
end

class Register \< ActiveRecord::Base  
belongs\_to :profile

def self.table\_name() “mhp\_register” end  
end

But Im getting the following error.

Showing _profile/index.rhtml_ where line _#4_ raised:

You have a nil object when you didn’t expect it!  
The error occurred while evaluating nil.language\_speak

Any idea what am I doing wrong…I have only one controller for profile  
as  
follows

class ProfileController \< ApplicationController  
def index  
@result = Profile.find(:all)  
end  
end

–  
Regards

Haris G.

---

<div class="post-metadata">

**Author:** ![Haris\_G](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/h/8edcca/32.png) [@Haris\_G](https://www.ruby-forum.com/u/Haris_G)\
**Post date:** [January 2, 2008, 10:51am UTC](https://www.ruby-forum.com/t/nil-object-error/124762/2 "2008-01-02T10:51:08Z")

</div>

The profile may not have the register in mhp\_register table.  
Check whether there is any record for the profile in mhp\_register table.  
Or else, the table attribute name might be incorrect.

- Karthik.

---

<div class="post-metadata">

**Author:** ![Haris\_G](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/h/8edcca/32.png) [@Haris\_G](https://www.ruby-forum.com/u/Haris_G)\
**Post date:** [January 2, 2008, 2:09pm UTC](https://www.ruby-forum.com/t/nil-object-error/124762/3 "2008-01-02T14:09:40Z")

</div>

On Jan 2, 2008, at 3:42 AM, Haris G. wrote:

> Hello all,
> 
> Im getting a nil object error. here under are the details of my  
> app. My index.rhtml file is
> 
> \<% @result.each do |res| %\>  
> \<%= res.first\_name %\>  
>   
>   
> \<%= res.register.language\_speak %\>

I provided a possible solution in the other thread you asked this in.

Peace,  
Phillip
