ensl.org/app/controllers/weeks_controller.rb

49 lines
980 B
Ruby
Raw Normal View History

class WeeksController < ApplicationController
before_action :get_week, except: [:new, :create]
def new
@week = Week.new
2014-03-31 21:33:16 +00:00
@week.contest = Contest.find(params[:id])
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))
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
end
end
def update
raise AccessError unless @week.can_update? cuser
if @week.update_attributes(Week.params(params, cuser))
flash[:notice] = t(:weeks_update)
redirect_to @week.contest
else
2014-03-31 21:33:16 +00:00
render :edit
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])
end
end