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? -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Danny Burkes
2008-Dec-18 07:22 UTC
Re: How would I find all "players" on an "active team"?
> @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. -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
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 Sanders <rails-mailing-l...-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> 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? > -- > Posted viahttp://www.ruby-forum.com/.--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Danny Burkes 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? -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---