Making more messes with mashes, maps, and requesters. Maybe a teensy

bit closer on the tournament pairing algorithm (???)  ActiveRecord
associations are kind of a pain, btw.
This commit is contained in:
Dan Buch
2012-03-09 00:24:48 -05:00
parent ec6d9d5146
commit 8ad33d18b7
10 changed files with 123 additions and 29 deletions

View File

@@ -11,10 +11,9 @@ class MashesController < ApplicationController
@map_a, @map_b = Map.pair
@mash = Mash.new(
:requester => request.remote_ip,
:map_a => @map_a.id,
:map_b => @map_b.id,
:winner => @map_a.id
:map_a => @map_a,
:map_b => @map_b,
:winner => @map_a
)
respond_to do |format|
@@ -23,15 +22,25 @@ class MashesController < ApplicationController
end
def create
mash_params = params[:mash]
mash_params[:requester] = request.remote_ip
logger.info("Got mash params: #{mash_params.inspect}")
mash_params = params[:mash].clone
logger.info("Got params: #{params.inspect}")
requester = Requester.find_or_initialize_by_ip(request.remote_ip)
requester.save!
requester.reload
logger.info("Setting mash.requester_id from #{requester.inspect}")
logger.info("Creating mash with: #{mash_params.inspect}")
@mash = Mash.new(mash_params)
@winner = Map.find(@mash.winner)
@mash.requester_id = requester.id
@winner = Map.find(@mash.winner_id.to_i)
@winner.points += 1
logger.info("About to save #{@mash.inspect}")
respond_to do |format|
if @mash.save && @winner.save
if @winner.save && @mash.save
flash[:notice] = 'Mash was successfully created.'
format.html { redirect_to(:action => 'new') }
else