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

  • Home
  • SEARCH
  • 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 6736395
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T11:07:29+00:00 2026-05-26T11:07:29+00:00

something what should really be easy and I can’t get it to work… I

  • 0

something what should really be easy and I can’t get it to work…
I have a Relation which has_many Contacts and Contact belongs_to Relation. Now I want to show the relation name in the contact index view. In the contacts controller I have this:

@contacts = Contact.paginate :page     => params[:page],
                             :include  => :relations,
                             :per_page => 10,
                             :order    => "last_name"

Now I expect in the index view to be able to use this:

<%= contact.relation.name %>

But it returns a undefined method "name" for nil:NilClass error? Thanks for your help!

  • 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-26T11:07:29+00:00Added an answer on May 26, 2026 at 11:07 am

    My guess is that you have at least one Contact object that doesn’t have an associated Relation object, which is why it’s trying to call .name on a nil value.

    You can try doing something like this temporarily to see if you have some Contacts without Relations:

    <%= contact.relation.name rescue "MISSING NAME" %>
    

    and see what gets displayed.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This really should be easy, but I just can't work it out myself, the
I'm struggling with something that should be really easy I think. I have a
This might be something very straight forward and I really think it should work
I get the feeling this is probably something I should know but I can't
This should be really easy but I can't figure out how to make it
I'm attempting to do something which should be relatively simple. I'm using a ListView
This is probably a really easy question, but I can't find anything that works.
I'm trying to do something that used to be really easy before the start
This should be really easy, I just want to update the listview when the
I am getting a bit frustrated with prism. Something that should be so easy

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.