undefined method `each'' for 0:Fixnum
at line
@school = School.find_by_title(params[:school_id].gsub(''-'',
" "))
for team in @school.teams
........
end
@school does exist cause i tried with .find(:first) and it gave the
same error.
Also I''m getting
undefined method `reject'' for #<Game:0x24ca1c4>
From @home.game_ids = @game
@game = Game.new(params[:game])
@game.opponent = params[:team][:name]
@home = Team.find_by_user_id(current_user.id)
@opponent = Team.find_by_name(@game.opponent)
if @game.save
flash[:notice] = ''Game was successfully created.''
@home.game_ids = @game
@opponent.game_ids = @game
Here are my models
class Game < ActiveRecord::Base
has_and_belongs_to_many :teams
end
class Player < ActiveRecord::Base
belongs_to :team
end
class School < ActiveRecord::Base
has_many :teams
belongs_to :users
def to_param
"#{title.gsub(/[^a-z0-9]+/i, ''-'')}"
end
end
class Team < ActiveRecord::Base
has_many :players
has_and_belongs_to_many :games
belongs_to :school
belongs_to :user
def to_param
"#{name.gsub(/[^a-z0-9]+/i, ''-'')}"
end
end
class User < ActiveRecord::Base
has_one :team
has_one :school
end
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---
edberner wrote:> undefined method `each'' for 0:Fixnum > at line > @school = School.find_by_title(params[:school_id].gsub(''-'', " ")) > > for team in @school.teams > ........ > > endNot sure about this one, but it looks like @school.teams is returning a 0, not an array of teams. "each" is called for you when you use a for/in loop. It is the equivalent of @school.teams.each { |team| ... } So "undefined method `each'' for 0:Fixnum" means "each" is being called on the integer 0.> Also I''m getting > undefined method `reject'' for #<Game:0x24ca1c4> > From @home.game_ids = @game > > @home.game_ids = @game > @opponent.game_ids = @gamegame_ids= is expecting an array of integers, your are passing it a model object. You probably just want to insert the game in the existing association. Try this: @home.games << @game @opponent.games << @game -- 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 -~----------~----~----~----~------~----~------~--~---
Thanks. It is starting to make sense to stop referring to elements by their rudimentary primary and secondary ids. Why might it not be getting the array of teams. I clearly have it set up in the model? On Apr 7, 4:39 pm, Alex Wayne <rails-mailing-l...-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> edberner wrote: > > undefined method `each'' for 0:Fixnum > > at line > > @school = School.find_by_title(params[:school_id].gsub(''-'', " ")) > > > for team in @school.teams > > ........ > > > end > > Not sure about this one, but it looks like @school.teams is returning a > 0, not an array of teams. "each" is called for you when you use a > for/in loop. It is the equivalent of > > @school.teams.each { |team| ... } > > So "undefined method `each'' for 0:Fixnum" means "each" is being called > on the integer 0. > > > Also I''m getting > > undefined method `reject'' for #<Game:0x24ca1c4> > > From @home.game_ids = @game > > > @home.game_ids = @game > > @opponent.game_ids = @game > > game_ids= is expecting an array of integers, your are passing it a model > object. You probably just want to insert the game in the existing > association. Try this: > > @home.games << @game > @opponent.games << @game > -- > 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 -~----------~----~----~----~------~----~------~--~---
It''s interesting because now I get that same error here
undefined method `each'' for 1:Fixnum
def update
@game = Game.find(params[:id])
for team in @game.teams
team.increment! :games
end
On Apr 7, 4:39 pm, Alex Wayne
<rails-mailing-l...-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org>
wrote:> edberner wrote:
> > undefined method `each'' for 0:Fixnum
> > at line
> > @school =
School.find_by_title(params[:school_id].gsub(''-'', "
"))
>
> > for team in @school.teams
> > ........
>
> > end
>
> Not sure about this one, but it looks like @school.teams is returning a
> 0, not an array of teams. "each" is called for you when you use
a
> for/in loop. It is the equivalent of
>
> @school.teams.each { |team| ... }
>
> So "undefined method `each'' for 0:Fixnum" means
"each" is being called
> on the integer 0.
>
> > Also I''m getting
> > undefined method `reject'' for #<Game:0x24ca1c4>
> > From @home.game_ids = @game
>
> > @home.game_ids = @game
> > @opponent.game_ids = @game
>
> game_ids= is expecting an array of integers, your are passing it a model
> object. You probably just want to insert the game in the existing
> association. Try this:
>
> @home.games << @game
> @opponent.games << @game
> --
> 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
-~----------~----~----~----~------~----~------~--~---
Does anybody know why this is happening? Thanks. On Apr 7, 4:59 pm, edberner <eber...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> It''s interesting because now I get that same error here > undefined method `each'' for 1:Fixnum > > def update > @game = Game.find(params[:id]) > > for team in @game.teams > team.increment! :games > end > > On Apr 7, 4:39 pm, Alex Wayne <rails-mailing-l...-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> > wrote: > > > edberner wrote: > > > undefined method `each'' for 0:Fixnum > > > at line > > > @school = School.find_by_title(params[:school_id].gsub(''-'', " ")) > > > > for team in @school.teams > > > ........ > > > > end > > > Not sure about this one, but it looks like @school.teams is returning a > > 0, not an array of teams. "each" is called for you when you use a > > for/in loop. It is the equivalent of > > > @school.teams.each { |team| ... } > > > So "undefined method `each'' for 0:Fixnum" means "each" is being called > > on the integer 0. > > > > Also I''m getting > > > undefined method `reject'' for #<Game:0x24ca1c4> > > > From @home.game_ids = @game > > > > @home.game_ids = @game > > > @opponent.game_ids = @game > > > game_ids= is expecting an array of integers, your are passing it a model > > object. You probably just want to insert the game in the existing > > association. Try this: > > > @home.games << @game > > @opponent.games << @game > > -- > > 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 -~----------~----~----~----~------~----~------~--~---
Got it. Calling team.games returned the array of my association. Not the integer field I wanted. Changed field name and all is ok. On Apr 7, 5:11 pm, edberner <eber...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> Does anybody know why this is happening? Thanks. > > On Apr 7, 4:59 pm, edberner <eber...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > It''s interesting because now I get that same error here > > undefined method `each'' for 1:Fixnum > > > def update > > @game = Game.find(params[:id]) > > > for team in @game.teams > > team.increment! :games > > end > > > On Apr 7, 4:39 pm, Alex Wayne <rails-mailing-l...-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> > > wrote: > > > > edberner wrote: > > > > undefined method `each'' for 0:Fixnum > > > > at line > > > > @school = School.find_by_title(params[:school_id].gsub(''-'', " ")) > > > > > for team in @school.teams > > > > ........ > > > > > end > > > > Not sure about this one, but it looks like @school.teams is returning a > > > 0, not an array of teams. "each" is called for you when you use a > > > for/in loop. It is the equivalent of > > > > @school.teams.each { |team| ... } > > > > So "undefined method `each'' for 0:Fixnum" means "each" is being called > > > on the integer 0. > > > > > Also I''m getting > > > > undefined method `reject'' for #<Game:0x24ca1c4> > > > > From @home.game_ids = @game > > > > > @home.game_ids = @game > > > > @opponent.game_ids = @game > > > > game_ids= is expecting an array of integers, your are passing it a model > > > object. You probably just want to insert the game in the existing > > > association. Try this: > > > > @home.games << @game > > > @opponent.games << @game > > > -- > > > 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 -~----------~----~----~----~------~----~------~--~---