Hi, having this models:
class Formation < ActiveRecord::Base
has_many :positions, :dependent => :destroy
end
class TeamFormation < Formation
has_many :players, :through => :positions
end
class Position < ActiveRecord::Base
belongs_to :formation
belongs_to :player
end
I’m trying to modify position’s player attribute from a formation:
team.players.each do |player|
self.positions.each do |position|
if !self.players.include?(player) and !position.player
position.player = player <------------ HERE I'M TRYING TO
MODIFY PLAYER
break
end
end
end
The first time I create a formation an asign those values all works
fine, but once it’s created I
can’t modify position’s player attr because “can’t modify frozen hash”
error is raised.
How could I modify those values?, what am I doing wrong?