wblog/app/models/subscribe.rb

16 lines
462 B
Ruby
Raw Normal View History

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: '地址无效' }
def self.subscribe_list
Subscribe.all.where(enable: true).map(&:email)
end
def self.unsubscribe?(email)
Subscribe.where(email: email, enable: false).first.present?
end
end