box-o-sand/rails/map-mash/app/controllers/mashes_controller.rb

43 lines
986 B
Ruby
Raw Normal View History

2012-03-04 16:51:35 +00:00
class MashesController < ApplicationController
def redirect_to_new
flash[:notice] = 'Sneaky pete.'
redirect_to(:action => 'new')
2012-03-04 16:51:35 +00:00
end
alias_method :index, :redirect_to_new
alias_method :show, :redirect_to_new
2012-03-04 16:51:35 +00:00
def new
@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
)
2012-03-04 16:51:35 +00:00
respond_to do |format|
format.html
2012-03-04 16:51:35 +00:00
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)
@winner = Map.find(@mash.winner)
@winner.points += 1
2012-03-04 16:51:35 +00:00
respond_to do |format|
if @mash.save && @winner.save
2012-03-04 16:51:35 +00:00
flash[:notice] = 'Mash was successfully created.'
format.html { redirect_to(:action => 'new') }
2012-03-04 16:51:35 +00:00
else
format.html { render :action => 'new' }
2012-03-04 16:51:35 +00:00
end
end
end
end