2014-03-23 00:22:25 +00:00
|
|
|
class TeamersController < ApplicationController
|
2019-06-07 15:04:16 +00:00
|
|
|
def index
|
|
|
|
end
|
|
|
|
|
2014-03-23 00:22:25 +00:00
|
|
|
def create
|
2017-03-03 13:09:14 +00:00
|
|
|
@old_application = (cuser.teamers.joining.count == 0) ? nil : cuser.teamers.joining.first
|
2020-03-18 03:38:17 +00:00
|
|
|
@teamer = Teamer.new(Teamer.params(params, cuser))
|
|
|
|
raise AccessError unless @teamer.can_create?(cuser, Teamer.params(params, cuser))
|
2014-03-23 00:22:25 +00:00
|
|
|
@teamer.user = cuser unless cuser.admin?
|
|
|
|
|
|
|
|
if @teamer.save
|
|
|
|
flash[:notice] = t(:applying_team) + @teamer.team.to_s
|
2017-03-03 13:09:14 +00:00
|
|
|
@old_application && @old_application.destroy
|
2014-03-23 00:22:25 +00:00
|
|
|
else
|
|
|
|
flash[:error] = @teamer.errors.full_messages.to_s
|
|
|
|
end
|
|
|
|
|
|
|
|
redirect_to_back
|
|
|
|
end
|
|
|
|
|
2014-05-13 23:54:51 +00:00
|
|
|
def edit
|
|
|
|
teamer_id = params["teamer"]
|
|
|
|
@teamer = Teamer.find(teamer_id)
|
|
|
|
@teamer.team_id = params["id"]
|
|
|
|
@teamer.save
|
|
|
|
redirect_to_back
|
|
|
|
end
|
|
|
|
|
2014-03-23 00:22:25 +00:00
|
|
|
def destroy
|
|
|
|
@teamer = Teamer.find params[:id]
|
|
|
|
raise AccessError unless @teamer.can_destroy? cuser
|
|
|
|
|
|
|
|
@teamer.destroy
|
|
|
|
redirect_to_back
|
|
|
|
end
|
|
|
|
end
|