44 lines
1.1 KiB
Ruby
44 lines
1.1 KiB
Ruby
class MashesController < ApplicationController
|
|
def redirect_to_new
|
|
flash[:notice] = 'Sneaky pete.'
|
|
redirect_to(:action => 'new')
|
|
end
|
|
|
|
alias_method :index, :redirect_to_new
|
|
alias_method :show, :redirect_to_new
|
|
|
|
def new
|
|
@map_a, @map_b = Map.rand(2)
|
|
|
|
@mash = Mash.new(
|
|
:requester => request.remote_ip,
|
|
:map_a => @map_a.id,
|
|
:map_b => @map_b.id,
|
|
:winner => @map_a.id
|
|
)
|
|
|
|
respond_to do |format|
|
|
format.html
|
|
format.xml { render :xml => @mash }
|
|
end
|
|
end
|
|
|
|
def create
|
|
mash_params = params[:mash]
|
|
mash_params[:requester] = request.remote_ip
|
|
logger.info("Got mash params: #{mash_params.inspect}")
|
|
@mash = Mash.new(mash_params)
|
|
|
|
respond_to do |format|
|
|
if @mash.save
|
|
flash[:notice] = 'Mash was successfully created.'
|
|
format.html { redirect_to(:action => 'new') }
|
|
format.xml { render :xml => @mash, :status => :created, :location => @mash }
|
|
else
|
|
format.html { render :action => 'new' }
|
|
format.xml { render :xml => @mash.errors, :status => :unprocessable_entity }
|
|
end
|
|
end
|
|
end
|
|
end
|