Class: SportDbAdmin::TeamsController

Inherits:
SportDbAdminController show all
Defined in:
app/controllers/sport_db_admin/teams_controller.rb

Instance Method Summary collapse

Instance Method Details

#indexObject

GET /teams



8
9
10
11
# File 'app/controllers/sport_db_admin/teams_controller.rb', line 8

def index
  # make clubs default view
  index_clubs
end

#index_clubsObject



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'app/controllers/sport_db_admin/teams_controller.rb', line 18

def index_clubs
  @teams = Team.where( club: true )
  
  if params[:order].present?
    if params[:order] == 'key'
      @teams = @teams.order( 'key' )
    elsif params[:order] == 'title'
      @teams = @teams.order( 'title' )
    elsif params[:order] == 'code'
      @teams = @teams.order( 'code' )
    end
  else
    @teams = @teams.order( 'country_id' )
  end
  
  @teams = @teams.all
end

#index_national_teamsObject



13
14
15
16
# File 'app/controllers/sport_db_admin/teams_controller.rb', line 13

def index_national_teams
  # todo: join country table to order by country.key ??
  @teams = Team.where( club: false ).order( 'country_id' ).all
end

#shortcutObject

GET /:key e.g /barcelona or /rapid etc.



37
38
39
40
# File 'app/controllers/sport_db_admin/teams_controller.rb', line 37

def shortcut
  @team = Team.find_by_key!( params[:key] )
  render :show
end

#showObject

GET /teams/1



43
44
45
# File 'app/controllers/sport_db_admin/teams_controller.rb', line 43

def show
  @team = Team.find(params[:id])
end