You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
box-o-sand/rails/map-mash/app/controllers/mashes_controller.rb

43 lines
1.0 KiB

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
@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