wblog/app/models/subscribe.rb

16 lines
456 B
Ruby
Raw Permalink Normal View History

class Subscribe < ApplicationRecord
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_list
Subscribe.all.where(enable: false).map(&:email)
end
def self.unsubscribe?(email)
Subscribe.where(email: email, enable: false).first.present?
end
end