2014-04-01 17:09:10 +08:00
|
|
|
class Subscribe
|
|
|
|
include Mongoid::Document
|
|
|
|
field :email, type: String
|
|
|
|
field :enable, type: Mongoid::Boolean, default: true
|
|
|
|
|
2014-04-02 23:40:05 +08:00
|
|
|
validates :email, presence: true, uniqueness: true, format: { with: /\A([^@\s]+)@((?:[-a-z0-9]+\.)+[a-z]{2,})\z/i, message: '地址无效' }
|
2014-04-01 17:09:10 +08:00
|
|
|
|
|
|
|
def self.subscribe_list
|
2014-04-07 22:56:21 +08:00
|
|
|
Subscribe.all.where(enable: true).map(&:email)
|
|
|
|
end
|
|
|
|
|
|
|
|
def self.unsubscribe?(email)
|
|
|
|
Subscribe.where(email: email, enable: false).first.present?
|
2014-04-01 17:09:10 +08:00
|
|
|
end
|
|
|
|
end
|