Nil object error

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.

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.

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