ban fixes
This commit is contained in:
@@ -19,13 +19,12 @@ class BansController < ApplicationController
|
||||
end
|
||||
|
||||
def create
|
||||
@ban = Ban.new(params[:ban])
|
||||
@ban.banner_id = CurrentUser.id
|
||||
@ban = Ban.create(params[:ban])
|
||||
|
||||
if @ban.save
|
||||
redirect_to ban_path(@ban), :notice => "Ban created"
|
||||
else
|
||||
if @ban.errors.any?
|
||||
render :action => "new"
|
||||
else
|
||||
redirect_to ban_path(@ban), :notice => "Ban created"
|
||||
end
|
||||
end
|
||||
|
||||
@@ -34,6 +33,7 @@ class BansController < ApplicationController
|
||||
if @ban.update_attributes(params[:ban])
|
||||
redirect_to ban_path(@ban), :notice => "Ban updated"
|
||||
else
|
||||
puts @ban.errors.full_messages
|
||||
render :action => "edit"
|
||||
end
|
||||
end
|
||||
|
||||
@@ -5,11 +5,16 @@ class Ban < ActiveRecord::Base
|
||||
attr_accessible :reason, :duration, :user_id, :user_name
|
||||
validate :user_is_inferior
|
||||
validates_presence_of :user_id, :reason, :duration
|
||||
before_validation :initialize_banner_id, :on => :create
|
||||
|
||||
def self.is_banned?(user)
|
||||
exists?(["user_id = ? AND expires_at > ?", user.id, Time.now])
|
||||
end
|
||||
|
||||
def initialize_banner_id
|
||||
self.banner_id = CurrentUser.id
|
||||
end
|
||||
|
||||
def user_is_inferior
|
||||
if user
|
||||
if user.is_admin?
|
||||
|
||||
Reference in New Issue
Block a user