Commit 4edecb12 by Rocky Duan

validation for tags

parent 4929361f
...@@ -32,6 +32,8 @@ class CommentThread < Content ...@@ -32,6 +32,8 @@ class CommentThread < Content
validates_presence_of :course_id # do we really need this? validates_presence_of :course_id # do we really need this?
validates_presence_of :commentable_id validates_presence_of :commentable_id
validate :valid_tag_names
after_create :generate_notifications after_create :generate_notifications
def root_comments def root_comments
...@@ -94,5 +96,11 @@ private ...@@ -94,5 +96,11 @@ private
end end
end end
def valid_tag_names
unless tags_array.all? {|tag| tag =~ /^\w+(\s*\w+)*$/}
errors.add :tag, "must consist of words, numbers, underscores and spaces only"
end
end
handle_asynchronously :generate_notifications handle_asynchronously :generate_notifications
end end
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment