Sha256: 74f6fd4bc529b60cc17d52ef4e29dbdb433b4beb97a406b81d54d77f9aa11ac2

Contents?: true

Size: 1.62 KB

Versions: 5

Compression:

Stored size: 1.62 KB

Contents

class AdminController < ApplicationController
  before_filter :login_required
  include SavesPicks

  def edit
    @entry = Entry.find_by_user_id(current_user.id)
    if @entry
      @pool = @entry.pool
      save_picks(@entry)
      if @entry.save
        @pool.pool.tournament_entry = @entry.tournament_entry
        @pool.save
        flash[:info] = "Tournament bracket updated."
        redirect_to :action => 'bracket', :id => @pool.id
      else
        flash[:error] = "Could not save entry."
        render :action => 'bracket', :layout => 'bracket'
      end
    else
      flash[:error] = "Tournament bracket has not yet been initialized."
    end
  end

  def entries
    @pool = Pool.find(params[:id])
  end

  def index
    @pools = Pool.find(:all)
  end

  def pool
    @available_scoring_strategies = Tournament::ScoringStrategy.available_strategies.map{|n| Tournament::ScoringStrategy.strategy_for_name(n)}
    @pool = params[:id] ? Pool.find(params[:id]) : Pool.new
    if request.post?
      @pool.attributes = params[:pool]
      @pool.user_id ||= current_user.id
      if @pool.valid?
        @pool.save!
        # reload it
        @pool = Pool.find(@pool.id)
      end
    end
  end

  def bracket
    pool = Pool.find(params[:id])
    # This is confusing ...
    @pool = pool.pool
    @entry = Entry.find_or_initialize_by_user_id(:user_id => current_user.id, :pool_id => pool.id, :tie_break => 0, :name => 'Tournament Bracket')
    @entry.bracket
    @entry.save!
      
    render :layout => 'bracket'
  end

  def authorized?(action = action_name, resource = nil)
    return super && admin_authorized?(action_name, resource)
  end

end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
tournament-2.1.2 webgui/app/controllers/admin_controller.rb
tournament-2.1.0 webgui/app/controllers/admin_controller.rb
tournament-2.1.1 webgui/app/controllers/admin_controller.rb
tournament-2.2.0 webgui/app/controllers/admin_controller.rb
tournament-2.0.0 webgui/app/controllers/admin_controller.rb