epaper/app/models/e_paper_subscriber.rb

20 lines
509 B
Ruby
Raw Normal View History

2019-05-28 15:54:32 +00:00
class EPaperSubscriber
include Mongoid::Document
include Mongoid::Timestamps
2022-12-02 03:47:34 +00:00
field :email, type: String
2019-05-28 15:54:32 +00:00
field :subscribed, type: Boolean, :default => true
field :language
field :last_paper_sent
2022-12-02 03:47:34 +00:00
before_save do
self.fix_email
if self.class.where(:email=>self.email, :language=>self.language,:subscribed=>true).count != 0
return false
end
end
def fix_email(save_flag=false)
self.email = self.email.to_s.gsub(/[  ]/,'').sub(/;$/, '')
self.save if save_flag
end
2019-05-28 15:54:32 +00:00
end