app/models/story.rb
def check_tags
    u = self.editor || self.user

    self.taggings.each do |t|
      if !t.tag.valid_for?(u)
        raise "#{u.username} does not have permission to use privileged " <<
          "tag #{t.tag.tag}"
      elsif t.tag.inactive? && !t.new_record? && !t.marked_for_destruction?
        # stories can have inactive tags as long as they existed before
        raise "#{u.username} cannot add inactive tag #{t.tag.tag}"
      end
    end

    if !self.taggings.reject{|t| t.marked_for_destruction? || t.tag.is_media?
    }.any?
      errors.add(:base, "Must have at least one non-media (PDF, video) " <<
        "tag.  If no tags apply to your content, it probably doesn't " <<
        "belong here.")
    end
  end
# this has to happen just before save rather than in tags_a= because we need
# to have a valid user_id
this has to happen just before save rather than in tags_a= because we need
to have a valid user_id
this has to happen just before save rather than in tags_a = because we need to have a valid user_id
def check_tags
    u = self.editor || self.user
    self.taggings.each do |t|
      if !t.tag.valid_for?(u)
        raise "#{u.username} does not have permission to use privileged " <<
          "tag #{t.tag.tag}"
      elsif t.tag.inactive? && !t.new_record? && !t.marked_for_destruction?
        raise "#{u.username} cannot add inactive tag #{t.tag.tag}"
      end
    end
    if !self.taggings.reject{|t| t.marked_for_destruction? || t.tag.is_media?
    }.any?
      errors.add(:base, "Must have at least one non-media (PDF, video) " <<
        "tag.  If no tags apply to your content, it probably doesn't " <<
        "belong here.")
    end
  end
def check_tags u = self . editor || self . user self . taggings . each do | t | if ! t . tag . valid_for? ( u ) raise "#{u.username} does not have permission to use privileged " << "tag #{t.tag.tag}" elsif t . tag . inactive? && ! t . new_record? && ! t . marked_for_destruction? raise "#{u.username} cannot add inactive tag #{t.tag.tag}" end end if ! self . taggings . reject { | t | t . marked_for_destruction? || t . tag . is_media? } . any? errors . add ( :base , "Must have at least one non-media (PDF, video) " << "tag.  If no tags apply to your content, it probably doesn't " << "belong here." ) end end
this has to happen just before save rather than in tags_a= because we need
to have a valid user_id
this has to happen just before save rather than in tags_a = because we need to have a valid user_id
# stories can have inactive tags as long as they existed before