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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T22:12:28+00:00 2026-05-25T22:12:28+00:00

module App::Models class Team < Base has_many :players […] end class Player < Base

  • 0
module App::Models
  class Team < Base
    has_many :players
    [...]
  end

  class Player < Base
    belongs_to :team
  end

When calling @team.players (or @player.team):

NoMethodError at /team/red
undefined method `players' for [#<App::Models::Team (...)>]:ActiveRecord::Relation

Am I using it wrong?

  • 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-25T22:12:28+00:00Added an answer on May 25, 2026 at 10:12 pm

    Note that you’re calling players on an instance of ActiveRecord::Relation. You don’t actually have one Team, you have a query of several teams. Simply append .first to your definition of @team to get the first team:

    class TeamX
      def get(name)
        @team = Team.where(:name => name).first
      end
    end
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

These are my models: class Company < ActiveRecord::Base has_many :products end class Product <
In my rails app I have a models/foo.rb and models/foo/exceptions.rb : class Foo include
I have a ruby app that uses ActiveRecord. I have the following models module
This module is part of a simple todo app I made with Python... def
I'm trying to finish a little module from a reporting app using external dlls.
I'm developing a Django app, and I'm trying to use Python's logging module for
I have module application. When I run it, the main window of that app
Possible Duplicate: How can I parse JSON in Google App Engine? json module was
module Superpower # instance method def turn_invisible ... end # module method def Superpower.turn_into_toad
Here is my model class RecipeIngredient(models.Model): recipe = models.ForeignKey(Recipe) ingredient = models.ForeignKey(Ingredient) serving_size =

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.