How would I find all "players" on an "active team"?

I’m trying to find all players on an active team, and this is just
stumping me.

I defined the “active team” by:

@active_team = Team.find(:all, :conditions => [“active=?”, true])

Now, I’m trying to use in my loop:

@active_team.players

but that just gives me an “undefined method `players’”. I know I’m
probably missing something really simple. Any idea?

@active_team = Team.find(:all, :conditions => [“active=?”, true])

The result of find(:all,…) is an array

Now, I’m trying to use in my loop:

@active_team.players

You want @active_team.each {|t| t.players}

or some such.

Do you have:

has_many :players

in your Team model?

In order to access players in a team or team in Player object you must
define relations in the model. In the later case it should be:

belongs_to :team

On Dec 18, 7:57 am, Bob S. [email protected]

Danny B. wrote:

@active_team = Team.find(:all, :conditions => [“active=?”, true])

The result of find(:all,…) is an array

Now, I’m trying to use in my loop:

@active_team.players

You want @active_team.each {|t| t.players}

or some such.

Hi Danny,

I tried the @active_team.each {|t| t.players}, but it’s not working for
me. It’s reading the contents of the Team model for some reason. Is
there an alternative way that might work?