# class LeaguesController

### Public Instance Methods

create() click to toggle source

implemented and partially tested

    # File app/controllers/leagues_controller.rb, line 5
    def create
        @league = League.new(params[:league])
        @league.creator_id = current_user.id
        # attempt to save league so as to get its id
        if @league.save == true
          # Need to reload to get the league id back after the save
          @league.reload
          # Create the signed in user's portfolio as a league manager
          @portfolio = create_manager_portfolio(@league)
          if @portfolio.save
            # Flash a success message
            flash[:success] = "Created your league!"
            # Send them to the league
            redirect_to @league
          else
            logger.info("Portfolio creation failed.")
            @league.delete
            flash[:fail] = "Sorry, portfolio couldn't be created."
            render 'new'
          end
        else
          logger.info(@league.errors.full_messages)
          logger.info("League creation failed.")
          flash[:fail] = @league.errors.full_messages;
          render 'new'
        end
    end

destroy() click to toggle source

not implemented

    # File app/controllers/leagues_controller.rb, line 55
    def destroy
    end

edit() click to toggle source

not implemented

    # File app/controllers/leagues_controller.rb, line 74
    def edit
    end

index() click to toggle source

implemented and partially tested

    # File app/controllers/leagues_controller.rb, line 34
    def index
      #Get an array of all leagues
      @leags = League.all

      #Set a variable to false for later
      @filtered = false

      #If we are filtering, we want to go in here
      if params[:filter] != nil
        #Lessen the array we had according to the filter set
        @leags = League.where("name LIKE ?", "%"+params[:filter]+"%")

        #Set the variable from before to true so we know that we did infact filter.
        @filtered = true
      end

      #Save this for later just incase we want to paginate with different pages
      @leagues = League.where(:private => false).paginate(:page => params[:page])
    end

new() click to toggle source

implemented, shouldn't need to be tested...

    # File app/controllers/leagues_controller.rb, line 80
    def new
      @league = League.new
    end

show() click to toggle source

implemented and partially tested

    # File app/controllers/leagues_controller.rb, line 59
    def show
        if flash[:focus] == true
          @focus = true
        end
       @league = League.find(params[:id])
       @title = @league.name

       # List of portfolios to render
       @portfolios = Portfolio.where(:league_id=>@league.id).paginate(:page=>params[:page], :per_page=>10)
       # Create a local portfolio if user isn't in league and decides to join
       @portfolio = Portfolio.where("user_id = ? AND league_id = ?",current_user.id, @league.id).first
       @portfolio = @league.portfolios.build if @portfolio.nil?
    end

update() click to toggle source

    # File app/controllers/leagues_controller.rb, line 76
    def update
    end