Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 745995
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T09:38:52+00:00 2026-05-14T09:38:52+00:00

I am making good progress with my first Rails app with a lot of

  • 0

I am making good progress with my first Rails app with a lot of help from the great community here at Stack Overflow.

I have a basic application that has the following models:

kase
person
company
party

I have associated them in the following way:

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

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:

<li>Client Company: <span><%=h @kase.company.companyname %></span></li>

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:

<li>Person Company: <span><%=h @person.company.company_id %></span></li>

If I change the above to:

<li>Person Company: <span><%=h @person.company.companyname %></span></li>

I get the following error:

undefined method `company' for #<Person:0x105dc4938>

So it seems I can call the company ID, but nothing else from the company database, any ideas where I am going wrong?

Thanks,

Danny

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-14T09:38:53+00:00Added an answer on May 14, 2026 at 9:38 am

    You have

    class Person < ActiveRecord::Base
      has_and_belongs_to_many :kases
    end
    

    This means that you can do

    @person = Person.find(1)
    @person.kases.each do |kase|
      puts kase.company.name
    end
    

    But keep in mind that, in order for @person.company to work, you would need to have one of the following:

    class Person < ActiveRecord::Base
      belongs_to :company  # option 1
      has_one :company     # option 2
    end
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am working on my first iPhone app and making good progress. But there
Making good progress on rails now, but hit a snag on heroku deployment. After
Good afternoon. I have been making a small openGL based app for android that
Does anyone have any good starting points for me when looking at making web
I would like to start making code patches to Rails. Are there any good
Making my first steps with NHibernate, I'm trying to have it creating my Tables
I'm looking for a good tutorial about making plugins for rails. Something about ActiveRecords
Does anyone have a good team building exercise to help bring together disparate teams
Good people - Need a little help. I am making a site that will
I am relatively new to Linq to Entities but I am making good progress.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.