This repository has been archived on 2024-03-16. You can view files and clone it, but cannot push or open issues or pull requests.
2012-11-20 17:56:30 +00:00
|
|
|
class CoAuthor
|
|
|
|
include Mongoid::Document
|
|
|
|
|
|
|
|
LANGUAGE_TYPES = [ "English", "Chinese" ]
|
|
|
|
|
|
|
|
field :name_id, type: BSON::ObjectId
|
|
|
|
field :co_author, localize: true
|
|
|
|
field :email
|
|
|
|
field :type
|
|
|
|
|
2012-12-03 04:10:45 +00:00
|
|
|
has_and_belongs_to_many :co_author_relations
|
2012-11-20 17:56:30 +00:00
|
|
|
|
2012-11-29 14:37:13 +00:00
|
|
|
VALID_EMAIL_REGEX = /\A[\w+\-.]+@[a-z\d\-.]+\.[a-z]+\z/
|
2012-11-20 17:56:30 +00:00
|
|
|
validates :email, format: { with: VALID_EMAIL_REGEX },
|
2012-11-29 14:37:13 +00:00
|
|
|
allow_blank: true,
|
2012-11-20 17:56:30 +00:00
|
|
|
uniqueness: { case_sensitive: false }
|
|
|
|
|
|
|
|
validates :co_author, presence: true
|
2012-11-29 14:37:13 +00:00
|
|
|
before_save { |coauthor| coauthor.email = email.downcase if not coauthor.email.nil?}
|
2012-11-20 17:56:30 +00:00
|
|
|
end
|
|
|
|
|