From 7db2fecbb1f05c478a05fb373286521d4d6978de Mon Sep 17 00:00:00 2001 From: juandefelix Date: Sat, 3 Oct 2015 11:54:48 -0500 Subject: [PATCH] added validation for tag count --- app/models/concerns/taggable.rb | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/app/models/concerns/taggable.rb b/app/models/concerns/taggable.rb index 1cce0152d..52efc04a7 100644 --- a/app/models/concerns/taggable.rb +++ b/app/models/concerns/taggable.rb @@ -3,6 +3,7 @@ module Taggable included do acts_as_taggable + validate :max_number_of_tags end def tag_list_with_limit(limit = nil) @@ -17,4 +18,8 @@ module Taggable count = tags.size - limit count < 0 ? 0 : count end + + def max_number_of_tags + errors.add(:tag_list, :less_than_or_equal_to, count: 6) if tag_list.count > 6 + end end