diff --git a/app/assets/javascripts/discourse/templates/modal/edit_category.js.handlebars b/app/assets/javascripts/discourse/templates/modal/edit_category.js.handlebars
index 7c87ec498ac..27d581469ef 100644
--- a/app/assets/javascripts/discourse/templates/modal/edit_category.js.handlebars
+++ b/app/assets/javascripts/discourse/templates/modal/edit_category.js.handlebars
@@ -1,7 +1,7 @@
-
+
\ No newline at end of file
diff --git a/app/assets/javascripts/discourse/views/modal/edit_category_view.js b/app/assets/javascripts/discourse/views/modal/edit_category_view.js
index 97e96254c01..56ad718e994 100644
--- a/app/assets/javascripts/discourse/views/modal/edit_category_view.js
+++ b/app/assets/javascripts/discourse/views/modal/edit_category_view.js
@@ -59,7 +59,12 @@ Discourse.EditCategoryView = Discourse.ModalBodyView.extend({
_this.saveSuccess(result);
},
error: function(errors) {
+ // displays a generic error message when none is sent from the server
+ // this might happen when some "after" callbacks throws an exception server-side
+ if(errors.length === 0) errors.push(Em.String.i18n("category.creation_error"));
+ // display the errors
_this.displayErrors(errors);
+ // not saving anymore
_this.set('saving', false);
}
});
diff --git a/app/models/category.rb b/app/models/category.rb
index 88ede172dd3..a2f93315e31 100644
--- a/app/models/category.rb
+++ b/app/models/category.rb
@@ -14,7 +14,7 @@ class Category < ActiveRecord::Base
has_many :featured_users, through: :category_featured_users, source: :user
validates :user_id, presence: true
- validates :name, presence: true, uniqueness: true
+ validates :name, presence: true, uniqueness: true, length: { in: 1..50 }
validate :uncategorized_validator
before_save :ensure_slug
@@ -27,7 +27,7 @@ class Category < ActiveRecord::Base
delegate :post_template, to: 'self.class'
def create_category_definition
- create_topic(title: I18n.t("category.topic_prefix", category: name), user: user, pinned_at: Time.now)
+ create_topic!(title: I18n.t("category.topic_prefix", category: name), user: user, pinned_at: Time.now)
update_column(:topic_id, topic.id)
topic.update_column(:category_id, id)
topic.posts.create(raw: post_template, user: user)
diff --git a/config/locales/client.en.yml b/config/locales/client.en.yml
index d599f2f29e4..87fca46e562 100644
--- a/config/locales/client.en.yml
+++ b/config/locales/client.en.yml
@@ -583,6 +583,7 @@ en:
view: 'View Topics in Category'
delete: 'Delete Category'
create: 'Create Category'
+ creation_error: There has been an error during the creation of the category.
more_posts: "view all {{posts}}..."
name: "Category Name"
description: "Description"
diff --git a/config/locales/client.fr.yml b/config/locales/client.fr.yml
index 8b8a29874ae..7fd2fb3e549 100644
--- a/config/locales/client.fr.yml
+++ b/config/locales/client.fr.yml
@@ -587,6 +587,7 @@ fr:
view: 'Voir les discussions dans cette catégorie'
delete: 'Supprimer la catégorie'
create: 'Créer la catégorie'
+ creation_error: "Il y a eu une erreur lors de la création de la catégorie."
more_posts: "voir tous les {{posts}}..."
name: "Nom de la catégorie"
description: "Description"