epaper/app/models/e_paper_subscriber.rb

20 lines
509 B
Ruby
Executable File
Raw Permalink Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

class EPaperSubscriber
include Mongoid::Document
include Mongoid::Timestamps
field :email, type: String
field :subscribed, type: Boolean, :default => true
field :language
field :last_paper_sent
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
end