views:

18

answers:

1

Hi Everyone,

At the moment in my application I can select a company from the company model when creating a new kase in the kase model.

<ul id="kases_new">
    <li>Company<span><%= f.select :company_id, Company.all.collect {|m| [m.companyname, m.id]} %></span></li>

This shows a list of the companies and then when I choose one it adds the company ID to the company_id field in the kases table.

I want to be able to add a second company to a kase but I don't know what the next step is. I have created a field in the kases table called appointedsurveyor_id so when I select the company it adds the company id to the appointedsurveyor_id field.

This works, but I need to be able to call information regarding that company like I would the first company.

<%= @kase.appointedsurveyor_id %>

The above returns the company_id number, but how do I return the company name, address and so on?

For the first company it is as simple as:

<li>Fax: <span><%=h @kase.company.companyfax %></span></li>

but if I do that a second time, I just get the first companies details.

Thanks,

Danny

+2  A: 

In your Kase model:

belongs_to :surveyor,
           :class_name => "Company",
           :foreign_key => "appointedsurveyor_id"

Then you have access to it via @kase.surveyor and have access to all the Company info.

Tony Fontenot
Perfect! Thanks!
dannymcc