ensl.org/app/controllers/bans_controller.rb

55 lines
1,003 B
Ruby
Raw Normal View History

class BansController < ApplicationController
before_action :get_ban, only: [:show, :edit, :update, :destroy]
def index
@bans = Ban.ordered
end
def show
end
def new
@ban = Ban.new
raise AccessError unless @ban.can_create? cuser
end
def edit
raise AccessError unless @ban.can_update? cuser
end
def create
@ban = Ban.new(Ban.params(params, cuser))
raise AccessError unless @ban.can_create? cuser
2017-03-04 21:45:05 +00:00
@ban.creator = cuser
if @ban.save
flash[:notice] = t(:bans_create)
redirect_to(@ban)
else
2014-03-31 21:33:16 +00:00
render :new
end
end
def update
raise AccessError unless @ban.can_update? cuser
if @ban.update_attributes(Ban.params(params, cuser))
flash[:notice] = t(:bans_update)
redirect_to(@ban)
else
2014-03-31 21:33:16 +00:00
render :edit
end
end
def destroy
raise AccessError unless @ban.can_destroy? cuser
@ban.destroy
redirect_to(bans_url)
end
private
def get_ban
@ban = Ban.find(params[:id])
end
end