81 lines
1.7 KiB
Ruby
81 lines
1.7 KiB
Ruby
class MashesController < ApplicationController
|
|
|
|
def index
|
|
@mashes = Mash.all
|
|
|
|
respond_to do |format|
|
|
format.html
|
|
format.xml { render :xml => @mashes }
|
|
end
|
|
end
|
|
|
|
def show
|
|
@mash = Mash.find(params[:id])
|
|
|
|
respond_to do |format|
|
|
format.html
|
|
format.xml { render :xml => @mash }
|
|
end
|
|
end
|
|
|
|
def new
|
|
map_a, map_b = Map.rand(2)
|
|
|
|
@mash = Mash.new(
|
|
:requestor => request.remote_ip,
|
|
:map_a => map_a.id,
|
|
:map_b => map_b.id,
|
|
:winner => 0
|
|
)
|
|
|
|
respond_to do |format|
|
|
format.html
|
|
format.xml { render :xml => @mash }
|
|
end
|
|
end
|
|
|
|
def edit
|
|
@mash = Mash.find(params[:id])
|
|
end
|
|
|
|
def create
|
|
@mash = Mash.new(params[:mash])
|
|
|
|
respond_to do |format|
|
|
if @mash.save
|
|
flash[:notice] = 'Mash was successfully created.'
|
|
format.html { redirect_to(@mash) }
|
|
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
|
|
|
|
def update
|
|
@mash = Mash.find(params[:id])
|
|
|
|
respond_to do |format|
|
|
if @mash.update_attributes(params[:mash])
|
|
flash[:notice] = 'Mash was successfully updated.'
|
|
format.html { redirect_to(@mash) }
|
|
format.xml { head :ok }
|
|
else
|
|
format.html { render :action => "edit" }
|
|
format.xml { render :xml => @mash.errors, :status => :unprocessable_entity }
|
|
end
|
|
end
|
|
end
|
|
|
|
def destroy
|
|
@mash = Mash.find(params[:id])
|
|
@mash.destroy
|
|
|
|
respond_to do |format|
|
|
format.html { redirect_to(mashes_url) }
|
|
format.xml { head :ok }
|
|
end
|
|
end
|
|
end
|