2014-02-09 07:54:03 +00:00
|
|
|
class ResourceCategory < ActiveRecord::Base
|
|
|
|
has_many :resources
|
2014-02-14 07:02:11 +00:00
|
|
|
attr_accessible :name
|
|
|
|
|
|
|
|
before_destroy :has_resources?
|
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
def has_resources?
|
|
|
|
errors.add(:base, "Cannot delete category with associated resources") unless resources.count == 0
|
|
|
|
errors.blank? #return false, to not destroy the element, otherwise, it will delete.
|
|
|
|
end
|
2014-02-09 07:54:03 +00:00
|
|
|
end
|