Note that there are some explanatory texts on larger screens.

plurals
  1. PORails show company name rather than company ID
    text
    copied!<p>I am making good progress with my first Rails app with a <em>lot</em> of help from the great community here at Stack Overflow.</p> <p>I have a basic application that has the following models:</p> <p>kase person company party</p> <p>I have associated them in the following way: </p> <pre><code>class Kase belongs_to :company # foreign key: company_id has_and_belongs_to_many :people # foreign key in join table class Person has_and_belongs_to_many :kases # foreign key in join table class Company has_many :kases has_many :people class Party has_and_belongs_to_many :people has_and_belongs_to_many :companies </code></pre> <p>At the moment, if I create a company and then go to create a new case (kase), I can choose from a drop down list the company I want (from the companies database) and then on the show view I can output the name of the chosen company for the case by using this code:</p> <pre><code>&lt;li&gt;Client Company: &lt;span&gt;&lt;%=h @kase.company.companyname %&gt;&lt;/span&gt;&lt;/li&gt; </code></pre> <p>However, if I add a new Person using the same method - I can successfully assign a company to the person, but on the show view it only outputs the company ID number using this code:</p> <pre><code>&lt;li&gt;Person Company: &lt;span&gt;&lt;%=h @person.company.company_id %&gt;&lt;/span&gt;&lt;/li&gt; </code></pre> <p>If I change the above to:</p> <pre><code>&lt;li&gt;Person Company: &lt;span&gt;&lt;%=h @person.company.companyname %&gt;&lt;/span&gt;&lt;/li&gt; </code></pre> <p>I get the following error:</p> <pre><code>undefined method `company' for #&lt;Person:0x105dc4938&gt; </code></pre> <p>So it seems I can call the company ID, but nothing else from the company database, any ideas where I am going wrong?</p> <p>Thanks,</p> <p>Danny</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload