Sha256: a201527adbc907e7000f341ec2432a74a425e68c6f0126ad0756c422a4b22ff9
Contents?: true
Size: 1.27 KB
Versions: 3
Compression:
Stored size: 1.27 KB
Contents
class Person < ActiveRecord::Base has_many :elts has_many :choices, :dependent => :destroy has_many :issues, :through => :choices, :source => :elt has_many :subscriptions, :dependent => :destroy has_many :subscribed_elts, :through => :subscriptions, :source => :elt has_many :person_mails, :dependent => :destroy has_many :mails, :through => :person_mails, :source => :mail has_many :visits, :dependent => :destroy has_many :visited, :through => :visits, :source => :elt has_many :old_visits, :dependent => :destroy has_many :old_visited, :through => :old_visits, :source => :elt validates_presence_of :name, :on => :create validates_length_of :name, :within => 3..80, :on => :create validates_uniqueness_of :name, :on => :create validates_uniqueness_of :email, :on => :create, :if => Proc.new { |p| p.email and p.email.length > 0 } # Convenience method, because User is as it was from the salted login plugin def user return User.find_by_login(name) end def before_create # Let's generate a nice looking id self.id ||= new_id = name.gsub(/\[[\w-]*\]/, '').strip \ .gsub(/\s/, '_').gsub(/[^\w]+/, '') \ .gsub(/_+/, '_').gsub(/(^_|_$)/, '') if name i = 0 self.id = "#{new_id}_#{i+=1}" while self.class.find_by_id self.id end end
Version data entries
3 entries across 3 versions & 1 rubygems
Version | Path |
---|---|
parlement-0.13 | app/models/person.rb |
parlement-0.14 | app/models/person.rb |
parlement-0.17 | app/models/person.rb |