ruby on rails - Call more than one item from a different model? -


In my application, currently I can select a company from the company model when creating a new cage in the case model.

  & lt; Ul id = "kases_new" & gt; & Lt; Li & gt; Company & lt; Span & gt; & Lt;% = f.select: company_id, Company.all.collect {| M [M.com.paninem, mid]}%> & Lt; / Span & gt; & Lt; / Li & gt;  

This shows a list of companies and then when I select one it adds the company ID to the case table in the company's IDEA.

I want to be able to add a second company to a cage, but I do not know what the next step is, I have created a field in the CAs table of appointmentsware_ID, so when I select the company I add this company ID to the Appointer_ID field.

This works, but I should be able to call information about that company as if I am the first company.

  & lt;% = @ kase.appointedsurveyor_id%>  

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

For the first company, it is as easy as:

   

But if I do this for the second time, then I get details of companies first.

Thanks,

Danny

In your cage model :

  related_ to: surveyor, class_name = & gt; "Company",: foreign_key => "Appointceurveyor_id"  

then you have access to it through @ kase.surveyor and have access to all the company information.


Comments