Class: TeamsController

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

Instance Method Summary collapse

Methods inherited from ApplicationController

#after_sign_in_path_for, #api_authenticate!, #current_project, #expire_revision!, #followed_projects, #no_cache, #oauth_authorize!, #read_revision, #require_login, #return_or_cache_revision!, #revision, #unfurling?, #with_current_project

Methods included from UrlHelper

#feature_path, #link_to_project_feature

Instance Method Details

#createObject



20
21
22
23
24
25
26
27
28
29
# File 'app/controllers/teams_controller.rb', line 20

def create
  @team = Team.new(team_attributes)

  if @team.save
    redirect_to teams_path, notice: "Team was successfully created."
  else
    flash.now[:error] = @team.errors[:base].join("\n")
    render action: "new"
  end
end

#destroyObject



50
51
52
53
54
55
56
57
# File 'app/controllers/teams_controller.rb', line 50

def destroy
  if @team.projects.unretired.none?
    @team.destroy
    redirect_to teams_url
  else
    render json: { base: ["#{@team.name.inspect} can't be deleted yet because it has unretired projects"] }, status: 422
  end
end

#editObject



32
33
34
35
# File 'app/controllers/teams_controller.rb', line 32

def edit
  @title = "Edit #{@team.name}"
  @team.roles.build(user: current_user, roles: ["Team Owner"]) if @team.roles.none?
end

#indexObject



6
7
8
9
10
# File 'app/controllers/teams_controller.rb', line 6

def index
  @title = "Teams"
  @teams = Team.all.preload(:projects, roles: :user).select { |team| can?(:read, team) }
  authorize! :read, :teams
end

#newObject



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

def new
  @title = "New Team"
  @team = Team.new
  @team.roles.build(user: current_user, roles: ["Team Owner"]) if @team.roles.none?
end

#updateObject



38
39
40
41
42
43
44
45
46
47
# File 'app/controllers/teams_controller.rb', line 38

def update
  @team.props.merge! team_attributes.delete(:props) if team_attributes.key?(:props)

  if @team.update_attributes(team_attributes)
    redirect_to teams_path, notice: "Team was successfully updated."
  else
    flash.now[:error] = @team.errors[:base].join("\n")
    render action: "edit"
  end
end