ban fixes

This commit is contained in:
albert
2011-10-27 19:35:43 -04:00
parent 3871188bde
commit 3372a93ef8
6 changed files with 30 additions and 26 deletions

View File

@@ -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

View File

@@ -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?