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 8724181
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T07:46:29+00:00 2026-06-13T07:46:29+00:00

I would really appreciate some help on this. I have relationships such as: class

  • 0

I would really appreciate some help on this.

I have relationships such as:

class User < ActiveRecord::Base
  has_many :ideas, :class_name => 'Challenge', :foreign_key => 'creator_id'
  has_many :contributions, :class_name => 'Challenge', :foreign_key => 'contributor_id'

class Challenge < ActiveRecord::Base
  belongs_to :creator, :class_name => 'User'
  belongs_to :contributor, :class_name => 'User'

My problem is being able to display the name rather than the id of a user in the views for the challenge model.

In the console I can assign a challenge to @challenge and then enter

@challenge.creator.name

which returns the name of the creator, perfect. But when I try to put this in my view it returns undefined method ‘name’.

I think that the closest to the correct thing that i’ve done is making the relevant part of my challenges index view say creator, instead of creator_id:

<tr><% @challenges.each do |challenge| %><tr>
<td><%= challenge.creator %></td>

but instead of returning the creator name in the view which is what I want, it returns the following output:

#<User:0x007fe1b81c20b8> 

Could anybody please explain why a field is displayed like this and how I can output the user’s name in my view.

My Challenges controller index action is just:

@challenges = Challenge.all
  • 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-06-13T07:46:30+00:00Added an answer on June 13, 2026 at 7:46 am

    I guess it must be displaying the object itself. challenge.creator is the object and not the name of the creator.

    Replace

    <td><%= challenge.creator %></td>
    

    With

    <td><%= challenge.creator.try :name %></td>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Would really appreciate some help with this. I have an app which consists of
I'm fairly new to SQL Server and would really appreciate some help with this.
I'm totally stumped on this error. Would really appreciate some help :). To reproduce
Ok, im pretty new at this and I would really appreciate some help, thanks!
I would really appreciate some help with the following issue: I have a gadget
OK Ladies and Gents, I would really appreciate some help: This is my table:
I would really appreciate it if some of you could help optimize my tables,
I would really appreciate if you could shed light on this problem. I have
Would really appreciate some help with a search angine I'm trying to make for
Hi I would really appreciate some help in forming a regex that removes a

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.