0

I need to be able to call data from a different model - not just one field, but any of them.

At the moment I have the following models:

kase
person
company
party

I can call information from the company to the kase and from the person to the kase using this:

<li>Client Company Address: <span class="address"><%=h @kase.company.companyaddress %></span></li>
<li>Case Handler: <span><%=h @kase.person.personname %></span></li>

Those two work, however if I add the following:

<li>Client Company Fax: <span><%=h @kase.company.companyfax %></span></li>
<li>Case Handler Tel: <span><%=h @kase.person.personmobile %></span></li>
<li>Case Handler Email: <span><%=h @kase.person.personemail %></span></li>

Any idea whats wrong?

Thanks,

Danny

EDIT: I get the following error message:

NoMethodError in Kases#show
Showing app/views/kases/show.html.erb where line #37 raised:

You have a nil object when you didn't expect it!
The error occurred while evaluating nil.personname

The lines that are noted are as follows:

34: <div id="clientinfo_showhide" style="display:none">
35: <li>Client Company Address: <span class="address"><%=h @kase.company.companyaddress  %></span></li>
36: <li>Client Company Fax: <span><%=h @kase.company.companyfax %></span></li>
37: <li>Case Handler: <span><%=h @kase.person.personname %></span></li>
38: <li>Case Handler Tel: <span><%=h @kase.person.personmobile %></span></li>
39: <li>Case Handler Email: <span><%=h @kase.person.personemail %></span></li>
40: </div>

The model for the kase is as follows:

class Kase
belongs_to :company # foreign key: company_id
belongs_to :person # foreign key in join table

The model for the person is as follows:

class Person
has_many :kases # foreign key in join table
belongs_to :company

The model for the company is as follows:

class Company
has_many :kases
has_many :people
def to_s; companyname; end

Hope this helps!

3
  • Is their any error message? Can you show us your models and migrations? Commented Apr 28, 2010 at 13:36
  • 1
    you should have person_id on kases table. Commented Apr 28, 2010 at 13:49
  • I have but it was a string, should it be integer? Commented Apr 28, 2010 at 13:55

2 Answers 2

2

Just to write a proper answer, the problem was he had the person_id on kases table as a string.

Sign up to request clarification or add additional context in comments.

Comments

0

Do you have the person table populated with data?

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.