Class: TeamsController
Instance Method Summary
collapse
#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
#create ⇒ Object
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
|
#destroy ⇒ Object
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
|
#edit ⇒ Object
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
|
#index ⇒ Object
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
|
#new ⇒ Object
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
|
#update ⇒ Object
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
|