2014-03-23 00:22:25 +00:00
|
|
|
class WeeksController < ApplicationController
|
2020-03-16 23:57:47 +00:00
|
|
|
before_action :get_week, except: [:new, :create]
|
2014-03-23 00:22:25 +00:00
|
|
|
|
|
|
|
def new
|
|
|
|
@week = Week.new
|
2014-03-31 21:33:16 +00:00
|
|
|
@week.contest = Contest.find(params[:id])
|
2014-03-23 00:22:25 +00:00
|
|
|
raise AccessError unless @week.can_create? cuser
|
|
|
|
end
|
|
|
|
|
|
|
|
def edit
|
|
|
|
raise AccessError unless @week.can_update? cuser
|
|
|
|
end
|
|
|
|
|
|
|
|
def create
|
2020-03-25 02:30:37 +00:00
|
|
|
@week = Week.new(Week.params(params, cuser))
|
2014-03-23 00:22:25 +00:00
|
|
|
raise AccessError unless @week.can_create? cuser
|
|
|
|
|
|
|
|
if @week.save
|
|
|
|
flash[:notice] = t(:weeks_create)
|
|
|
|
redirect_to @week.contest
|
|
|
|
else
|
2014-03-31 21:33:16 +00:00
|
|
|
render :new
|
2014-03-23 00:22:25 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def update
|
|
|
|
raise AccessError unless @week.can_update? cuser
|
|
|
|
|
2020-03-18 03:38:17 +00:00
|
|
|
if @week.update_attributes(Week.params(params, cuser))
|
2014-03-23 00:22:25 +00:00
|
|
|
flash[:notice] = t(:weeks_update)
|
|
|
|
redirect_to @week.contest
|
|
|
|
else
|
2014-03-31 21:33:16 +00:00
|
|
|
render :edit
|
2014-03-23 00:22:25 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def destroy
|
|
|
|
raise AccessError unless @week.can_destroy? cuser
|
|
|
|
@week.destroy
|
|
|
|
redirect_to_back
|
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
def get_week
|
2014-03-31 21:33:16 +00:00
|
|
|
@week = Week.find(params[:id])
|
2014-03-23 00:22:25 +00:00
|
|
|
end
|
|
|
|
end
|