ensl.org/app/controllers/weeks_controller.rb

49 lines
954 B
Ruby
Raw Permalink Normal View History

class WeeksController < ApplicationController
2014-03-31 21:33:16 +00:00
before_filter :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
@week = Week.new(params[:week])
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(params[:week])
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