class JournalPaperAuthor include Mongoid::Document include Mongoid::Timestamps field :name, type: String, localize: true field :email, type: String has_and_belongs_to_many :journal_papers has_and_belongs_to_many :journal_paper_author_types VALID_EMAIL_REGEX = /\A[\w+\-.]+@[a-z\d\-.]+\.[a-z]+\z/ validates :email, format: { with: VALID_EMAIL_REGEX }, allow_blank: true, uniqueness: { case_sensitive: false } before_save { |author| author.email = email.downcase if not author.email.nil?} end