the comments have an attribute called “admin” – is this a comment
added by an administrator
the ticket has an attribute called “admin_email_address”
I want to validate when saving the ticket and say “if I have a new
admin comment, make sure I have an admin_email_address”
In my ticket model, the method to do the validate looks like the
following and works as expected except for one thing. If the :_destroy
flag on the comment was set in my comment view partial (I want to
delete a comment), it seems like this iterating over the comments with
new_record? somehow resets that :_destroy flag.
Am I doing something wrong here? Or, could someone give me a hint on a
more simple way to do this validation.?
Thanks !!
new_admin_comments = false
self.comments.each do |comment|
new_admin_comments = true if comment.new_record? &&
comment.admin_comment == true
end
if admin_email.blank? && new_admin_comments == true
errors.add_to_base(“Admin email address required.”)
end