Avoid deleting categories which still have articles.

This commit is contained in:
benni 2012-12-11 10:53:01 +01:00
parent 620ec946f1
commit bae09624b7
3 changed files with 20 additions and 0 deletions

View file

@ -3,5 +3,13 @@ class ArticleCategory < ActiveRecord::Base
validates :name, :presence => true, :uniqueness => true, :length => { :in => 2..20 }
before_destroy :check_for_associated_articles
protected
def check_for_associated_articles
raise I18n.t('activerecord.errors.has_many_left', collection: Article.model_name.human) if articles.exists?
end
end