Handling mash creation, removing some unnecessary controller methods, redirecting some others to :action => 'new'.
This commit is contained in:
@@ -1,22 +1,11 @@
|
||||
class MashesController < ApplicationController
|
||||
|
||||
def index
|
||||
@mashes = Mash.all
|
||||
|
||||
respond_to do |format|
|
||||
format.html
|
||||
format.xml { render :xml => @mashes }
|
||||
end
|
||||
def redirect_to_new
|
||||
flash[:notice] = 'Sneaky pete.'
|
||||
redirect_to(:action => 'new')
|
||||
end
|
||||
|
||||
def show
|
||||
@mash = Mash.find(params[:id])
|
||||
|
||||
respond_to do |format|
|
||||
format.html
|
||||
format.xml { render :xml => @mash }
|
||||
end
|
||||
end
|
||||
alias_method :index, :redirect_to_new
|
||||
alias_method :show, :redirect_to_new
|
||||
|
||||
def new
|
||||
@map_a, @map_b = Map.rand(2)
|
||||
@@ -25,7 +14,7 @@ class MashesController < ApplicationController
|
||||
:requester => request.remote_ip,
|
||||
:map_a => @map_a.id,
|
||||
:map_b => @map_b.id,
|
||||
:winner => 'a'
|
||||
:winner => @map_a.id
|
||||
)
|
||||
|
||||
respond_to do |format|
|
||||
@@ -34,47 +23,20 @@ class MashesController < ApplicationController
|
||||
end
|
||||
end
|
||||
|
||||
def edit
|
||||
@mash = Mash.find(params[:id])
|
||||
end
|
||||
|
||||
def create
|
||||
@mash = Mash.new(params[:mash])
|
||||
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(@mash) }
|
||||
format.html { redirect_to(:action => 'new') }
|
||||
format.xml { render :xml => @mash, :status => :created, :location => @mash }
|
||||
else
|
||||
format.html { render :action => "new" }
|
||||
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
|
||||
|
Reference in New Issue
Block a user