Hi,
I’ve got my little app working pretty well. I’m using pretty much the
model and table layout from my previous thread, as suggested by Bill
Katz:
http://www.ruby-forum.com/topic/52506#26260
I have the Create page working and a delete Match page working, which
along with the appropriate record in the Matches table, removes the
linked items in the competitions table.
Now I’m working on the Update page and am not sure I’m doing it the
best way… not to mention it’s not working and looking at the log,
seems to make a ton of trips to the database. My Edit form includes:
(There are three more tags for the “blue” side, using
@match_teams[3] through 5)
The Edit controller defines @match_teams as:
@match = Match.find(params[:id])
@teams = Team.find(:all, :order => “number”)
@match_teams = []
@match.competitions.each do |team|
@match_teams << team.team_id
end
Now in the update method I’m doing this, but it looks messy and
doesn’t seem to update the correct records:
@match = Match.find(params[:id])
if @match.update_attributes(params[:match])
for i in 0…2
if @match.competitions[i].team_id != params[:Red][i] then
@match.competitions[i].team_id = params[:Red][i]
@match.competitions[i].save
end
end
for i in 3…5
if @match.competitions[i].team_id != params[:Blue][i] then
@match.competitions[i].team_id = params[:Blue][i]
@match.competitions[i].save
end
end
Is there a better way to do what I want… update all of the
corresponding changed items?
Thanks.
jt