class ResultsController < ApplicationController before_filter :authenticate_admin!, :except => [:index, :show] respond_to :html, :xml def index @results = Result.find(:all, :order => 'created_at DESC').paginate(:page => params[:page]) end def show @result = Result.find_by_short_url(params[:id]) || Result.find_by_id(params[:id]) respond_with(@result, :location => result_path) end def new @result = Result.new end def create @result = Result.create(params[:result]) if @result.save flash[:success] = 'Result uploaded successfully!' respond_with(@result, :location => @result) else flash[:error] = 'Upload failed.' respond_with(@result, :location => new_result_path) end end def edit @result = Result.find(params[:id]) end def update @result = Result.find(params[:id]) if @result.update_attributes(params[:result]) flash[:success] = 'Result was successfully updated.' respond_with(@result, :location => results_path) else flash[:error] = 'Oh snap. The hampsters stopped running. Try again.' respond_with(@result, :location => edit_result_path) end end def destroy @result = Result.find_by_short_url(params[:id]) @result.destroy flash[:success] = "The result was terminated. Pew pew pew." respond_with(nil, :location => results_path) end end