Files
old-zsterminator/app/controllers/teams_controller.rb

72 lines
1.8 KiB
Ruby
Raw Normal View History

2024-08-11 14:18:36 +02:00
class TeamsController < ApplicationController
2025-02-17 19:12:40 +01:00
before_action :set_company
before_action :set_team, only: %i[show edit update destroy]
2024-08-11 14:18:36 +02:00
# GET /teams or /teams.json
def index
@teams = Team.all
end
# GET /teams/1 or /teams/1.json
2025-02-17 19:12:40 +01:00
def show; end
2024-08-11 14:18:36 +02:00
# GET /teams/new
def new
@team = Team.new
end
# GET /teams/1/edit
2025-02-17 19:12:40 +01:00
def edit; end
2024-08-11 14:18:36 +02:00
# POST /teams or /teams.json
def create
@team = Team.new(team_params)
2025-02-17 19:12:40 +01:00
@team.company = @company
2024-08-11 14:18:36 +02:00
respond_to do |format|
if @team.save
2025-02-17 19:12:40 +01:00
format.html { redirect_to team_url(@team), notice: t('.team_created') }
2024-08-11 14:18:36 +02:00
format.json { render :show, status: :created, location: @team }
else
format.html { render :new, status: :unprocessable_entity }
format.json { render json: @team.errors, status: :unprocessable_entity }
end
end
end
# PATCH/PUT /teams/1 or /teams/1.json
def update
respond_to do |format|
if @team.update(team_params)
2025-02-17 19:12:40 +01:00
format.html { redirect_to team_url(@team), notice: t('.team_updated') }
2024-08-11 14:18:36 +02:00
format.json { render :show, status: :ok, location: @team }
else
format.html { render :edit, status: :unprocessable_entity }
format.json { render json: @team.errors, status: :unprocessable_entity }
end
end
end
# DELETE /teams/1 or /teams/1.json
def destroy
@team.destroy!
respond_to do |format|
2025-02-17 19:12:40 +01:00
format.html { redirect_to teams_url, notice: t('.team_destroyed') }
2024-08-11 14:18:36 +02:00
format.json { head :no_content }
end
end
private
2025-02-17 19:12:40 +01:00
# Use callbacks to share common setup or constraints between actions.
def set_team
@team = Team.find(params[:id])
end
# Only allow a list of trusted parameters through.
def team_params
params.require(:team).permit(:name, :description)
end
2024-08-11 14:18:36 +02:00
end