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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T13:09:47+00:00 2026-05-13T13:09:47+00:00

I am working on developing a skeleton of what to eventually become an administration

  • 0

I am working on developing a skeleton of what to eventually become an administration dashboard. One of the things the dashboard will eventually have to do is allow users to search for users of a game and view information about them. The information about them in question is in different table so naturally I have had to employ associations. For now, I am just trying to get an index set up so that I know the associations work before diving into getting search up and running.

I am trying to join a table called users with a table called bets through a table called bets_users. I have the model, controller, and index view working for the bets, however when I try to combine the bets model with the users model I am getting a NoMethodError in Bets#index.

Bet Model:

class Bet < ActiveRecord::Base
has_many :bets_bet_odds
has_many :bet_odds, :through => :bets_bet_odds

has_many :bets_users
has_many :users, :through => :bets_users  

def self.index_bets
find(:all, :joins => :users, :include => [:bets_users, :users])
end
end 

BetsUser Model

class BetsUser < ActiveRecord::Base

belongs_to :bet
belongs_to :user

end

User Model:

class User < ActiveRecord::Base

has_many :bets_users
has_many :bets, :through => :bets_users

end

Bets Controller

class BetsController < ApplicationController
def index
@index_bets = Bet.index_bets
end

def edit
@bet = Bet.find(params[:id])
end

def update
  @bet = Bet.find(params[:id])

if @bet.update_attributes(params[:bet])
  redirect_to :controller => "bets", :action => "index"
end
end

end

Bets Index View

<h1>Bets#index</h1>
<p>Find me in app/views/bets/index.html.erb</p>

<table border = "1">
<tr>
<th>id</th>
<th>user</th>
<th>scored</th>
<th>updated_at</th>
</tr>

<% @index_bets.each do |bet| %>
<tr>
<td><%= link_to h(bet.id), :controller => "bets",
                           :action     => "edit",
                           :id         =>  bet.id %>
</td>
<td><%=h bet.users.displayname %></td>
<td><%=h bet.scored %></td>
<td><%=h bet.updated_at %></td>
</tr>
<% end %>

</table>

The field I am trying to display in addition the data from the bets table is users.displayname. When I change displayname to id I no longer get an error, however the id that is displayed is not data from any of the tables. It is a long integer about 7 digits long.

Here is the error: Showing app/views/bets/index.html.erb where line #18 raised: undefined method `displayname’ for #

Here is the sql from my log file:

Processing BetsController#index (for 127.0.0.1 at 2010-01-24 14:48:22) [GET]
Bet Load (4600.9ms)     
SELECT `bets`.* FROM `bets` INNER JOIN      `bets_users` ON (`bets`.`id` = `bets_users`.`bet_id`) INNER JOIN `users` ON (`users`.`id` = `bets_users`.`user_id`) 
Bet Columns (97.4ms)   SHOW FIELDS FROM `bets`

  BetsUser Load (423.6ms)   SELECT `bets_users`.* FROM `bets_users` WHERE (`bets_users`.bet_id IN (3,4,5,12,13,14,15,16,17,18,19,21,24,25,27,28,29,31,33,34,35,42,43,44,45,50,51,52,54,61,70,71,72,73,74,76,77,80,81,82,87,92,93,94,95,96,97,98,100,101,102,103,110,112,113,114,116,120,121,122,123,125,127,129,130,131,132,133,134,135,136,137,138,139,140,141,142,143,144,145,148,149,151,152,153,154,155,156,157,158,159,160,161,162,163,164,166,167,168,169,170,171,172,173,174,178,179,180,181,182,183,186,187,188,189,190,191,192,193,196,197,198,199,200,201,202,203,204,205,206,207,211,212,213,214,215,216,220,221,222,223,224,225,226,227,228,229,230,231,232,233,234,288,289,290,291,292,293,294,295,296,297,298,299,300,301,302,303,306,307,308,309,310,311,312,313,314,315,316,317,318,319,320,321,324,325,326,327,328,329,330,331,332,333,334,335,336,337,338,339,340,341,342,343,344,345,384,403,410,411,412,417,431,432,433,439,440,441,466,470,471,472,473,474,475,479,480,481,482,483,484,487,488,489,490,491,492,493,494,495,496,497,498,499,500,501,502,503,504,505,506,515,516,517,518,519,520,521,522,523,524,525,526,527,528,529,530)) 
BetsUser Columns (95.6ms)  SHOW FIELDS FROM `bets_users`

User Columns (1063.6ms)   SHOW FIELDS FROM `users`
User Load (7109.4ms)   SELECT * FROM `users` WHERE (`users`.`id` IN (726,1,2,4)) 
  • 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-13T13:09:48+00:00Added an answer on May 13, 2026 at 1:09 pm

    bet.users is an Array (and not a User object) that’s why the .displayname doesn’t work.

    You could do bet.users.each {|user| user. displayname }

    The id you get is the id of the ruby object.

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

Sidebar

Ask A Question

Stats

  • Questions 269k
  • Answers 269k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer I'm certainly no Core Data expert, but reading the documentation… May 13, 2026 at 1:18 pm
  • Editorial Team
    Editorial Team added an answer Your game server would be an XMPP component which your… May 13, 2026 at 1:18 pm
  • Editorial Team
    Editorial Team added an answer You can't instantiate abstract classes, thus a vector of abstract… May 13, 2026 at 1:18 pm

Related Questions

I am working on developing a pair of libraries to work with a REST
I am working on developing a drupal site right now. I have created a
What are the primary reasons for using the Java EE (EJBs) over just a
I am working on developing an on-screen keyboard with java. This keyboard has a
I am developing a WPF UI application . I have a menu on top

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.