Avoid deleting categories which still have articles.
This commit is contained in:
parent
620ec946f1
commit
bae09624b7
3 changed files with 20 additions and 0 deletions
|
@ -12,6 +12,12 @@ class ArticleCategoriesController < ApplicationController
|
||||||
update!(:notice => "Die Kategorie wurde aktualisiert") { article_categories_path }
|
update!(:notice => "Die Kategorie wurde aktualisiert") { article_categories_path }
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def destroy
|
||||||
|
destroy!
|
||||||
|
rescue => error
|
||||||
|
redirect_to article_categories_path, alert: t('controller.article_categories.destroy.error', message: error.message)
|
||||||
|
end
|
||||||
|
|
||||||
protected
|
protected
|
||||||
|
|
||||||
def collection
|
def collection
|
||||||
|
|
|
@ -3,5 +3,13 @@ class ArticleCategory < ActiveRecord::Base
|
||||||
|
|
||||||
validates :name, :presence => true, :uniqueness => true, :length => { :in => 2..20 }
|
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
|
end
|
||||||
|
|
||||||
|
|
|
@ -21,6 +21,11 @@ de:
|
||||||
previous: "‹"
|
previous: "‹"
|
||||||
next: "›"
|
next: "›"
|
||||||
truncate: "..."
|
truncate: "..."
|
||||||
|
|
||||||
|
controller:
|
||||||
|
article_categories:
|
||||||
|
destroy:
|
||||||
|
error: 'Kategorie konnte nicht gelöscht werden: %{message}'
|
||||||
date:
|
date:
|
||||||
abbr_day_names:
|
abbr_day_names:
|
||||||
- So
|
- So
|
||||||
|
@ -216,6 +221,7 @@ de:
|
||||||
activerecord:
|
activerecord:
|
||||||
errors:
|
errors:
|
||||||
<<: *errors
|
<<: *errors
|
||||||
|
has_many_left: 'ist noch mit einem/r %{collection} verknüpft!'
|
||||||
models:
|
models:
|
||||||
article: Artikel
|
article: Artikel
|
||||||
supplier: Lieferant
|
supplier: Lieferant
|
||||||
|
|
Loading…
Reference in a new issue