Module: Account::Teams::ControllerBase
- Extended by:
- ActiveSupport::Concern, Controllers::Base
- Included in:
- Account::TeamsController
- Defined in:
- app/controllers/concerns/account/teams/controller_base.rb
Instance Method Summary collapse
-
#create ⇒ Object
POST /teams POST /teams.json.
-
#destroy ⇒ Object
# DELETE /teams/1 # DELETE /teams/1.json.
-
#edit ⇒ Object
GET /teams/1/edit.
-
#index ⇒ Object
GET /teams GET /teams.json.
-
#new ⇒ Object
GET /teams/new.
-
#show ⇒ Object
GET /teams/1 GET /teams/1.json.
-
#switch_to ⇒ Object
POST /teams/1/switch.
-
#update ⇒ Object
PATCH/PUT /teams/1 PATCH/PUT /teams/1.json.
Instance Method Details
#create ⇒ Object
POST /teams POST /teams.json
75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 |
# File 'app/controllers/concerns/account/teams/controller_base.rb', line 75 def create @team = Team.new(team_params) respond_to do |format| if @team.save # also make the creator of the team the default admin. @team.memberships.create(user: current_user, roles: [Role.admin]) current_user.current_team = @team current_user.former_user = false current_user.save format.html { redirect_to [:account, @team], notice: I18n.t("teams.notifications.created") } format.json { render :show, status: :created, location: [:account, @team] } else format.html { render :new, layout: "devise", status: :unprocessable_entity } format.json { render json: @team.errors, status: :unprocessable_entity } end end end |
#destroy ⇒ Object
# DELETE /teams/1 # DELETE /teams/1.json
113 114 115 116 117 118 119 120 121 122 123 |
# File 'app/controllers/concerns/account/teams/controller_base.rb', line 113 def destroy respond_to do |format| raise RemovingLastTeamException if current_user.one_team? @team.destroy format.html { redirect_to account_teams_url, notice: t("account.teams.notifications.destroyed") } format.json { head :no_content } rescue RemovingLastTeamException => _ format.html { redirect_to edit_account_team_url(@team), alert: t("account.teams.notifications.cannot_delete_last_team") } format.json { head :no_content } end end |
#edit ⇒ Object
GET /teams/1/edit
70 71 |
# File 'app/controllers/concerns/account/teams/controller_base.rb', line 70 def edit end |
#index ⇒ Object
GET /teams GET /teams.json
32 33 34 35 36 37 38 39 40 41 42 |
# File 'app/controllers/concerns/account/teams/controller_base.rb', line 32 def index # if a user doesn't have multiple teams, we try to simplify the team ui/ux # as much as possible. links to this page should go to the current team # dashboard. however, some other links to this page are actually in branch # logic and will not display at all. instead, users will be linked to the # "new team" page. (see the main account sidebar menu for an example of # this.) unless current_user.multiple_teams? redirect_to account_team_path(current_team) end end |
#new ⇒ Object
GET /teams/new
65 66 67 |
# File 'app/controllers/concerns/account/teams/controller_base.rb', line 65 def new render :new, layout: "devise" end |
#show ⇒ Object
GET /teams/1 GET /teams/1.json
53 54 55 56 57 58 59 60 61 62 |
# File 'app/controllers/concerns/account/teams/controller_base.rb', line 53 def show # I don't think this is the best place to close the loop on the onboarding process, but practically speaking it's # the easiest place to implement this at the moment, because all the onboarding steps redirect here on success. if session[:after_onboarding_url].present? redirect_to session.delete(:after_onboarding_url) end current_user.current_team = @team current_user.save end |
#switch_to ⇒ Object
POST /teams/1/switch
45 46 47 48 49 |
# File 'app/controllers/concerns/account/teams/controller_base.rb', line 45 def switch_to current_user.current_team = @team current_user.save redirect_to account_dashboard_path end |
#update ⇒ Object
PATCH/PUT /teams/1 PATCH/PUT /teams/1.json
99 100 101 102 103 104 105 106 107 108 109 |
# File 'app/controllers/concerns/account/teams/controller_base.rb', line 99 def update respond_to do |format| if @team.update(team_params) format.html { redirect_to [:account, @team], notice: I18n.t("teams.notifications.updated") } format.json { render :show, status: :ok, location: [:account, @team] } else format.html { render :edit, status: :unprocessable_entity } format.json { render json: @team.errors, status: :unprocessable_entity } end end end |