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?
Note that you’re calling
playerson an instance of ActiveRecord::Relation. You don’t actually have one Team, you have a query of several teams. Simply append.firstto your definition of@teamto get the first team: