This commit is contained in:
Toks
2015-01-05 14:10:20 -05:00
parent 325fc3e864
commit 9d1c31a06f

View File

@@ -6,7 +6,7 @@ class TagSubscription < ActiveRecord::Base
before_save :limit_tag_count
attr_accessible :name, :tag_query, :post_ids, :is_public, :is_visible_on_profile
validates_presence_of :name, :tag_query, :creator_id
validates_format_of :tag_query, :with => /\A(?:[^\r\n]*(?:\r?\n)*){1,20}\Z/, :message => "can have up to 20 queries"
validate :validate_number_of_queries
validate :creator_can_create_subscriptions, :on => :create
def normalize_name
@@ -38,6 +38,15 @@ class TagSubscription < ActiveRecord::Base
end
end
def validate_number_of_queries
if tag_query_array.size > 20 || tag_query_array.size < 1
self.errors.add(:tag_query, "can have up to 20 queries")
return false
else
return true
end
end
def tag_query_array
tag_query.scan(/[^\r\n]+/).map(&:strip)
end