orbit-basic/app/models/user/co_author.rb

21 lines
542 B
Ruby
Raw Normal View History

class CoAuthor
include Mongoid::Document
LANGUAGE_TYPES = [ "English", "Chinese" ]
field :name_id, type: BSON::ObjectId
field :co_author, localize: true
field :email
2012-12-03 09:16:28 +00:00
belongs_to :co_author_relations
VALID_EMAIL_REGEX = /\A[\w+\-.]+@[a-z\d\-.]+\.[a-z]+\z/
validates :email, format: { with: VALID_EMAIL_REGEX },
allow_blank: true,
2012-12-03 06:55:57 +00:00
uniqueness: { case_sensitive: false }
validates :co_author, presence: true
before_save { |coauthor| coauthor.email = email.downcase if not coauthor.email.nil?}
end