app/models/astrochimp/signup.rb in astrochimp-0.1.0 vs app/models/astrochimp/signup.rb in astrochimp-0.1.2

- old
+ new

@@ -1,19 +1,38 @@ module Astrochimp class Signup < ActiveRecord::Base # Attributes - attr_accessible :email + attr_accessible :email, :referrer_id # Constants STATUS_NEW = 0 STATUS_SUBSCRIBED = 1 STATUS_INVITED = 2 + # Relations + has_many :referrals, class_name: 'Signup' + belongs_to :referrer, class_name: 'Signup', counter_cache: true + # Validations validates :email, uniqueness: true, email: true # Callbacks before_create :add_email_to_mailchimp + + # Include referral code functionality + include IdCode + alias :referral_code :id_code + + # Return the referral code instead of id for urls + alias :to_param :referral_code + + def self.find(id_or_code) + if id_or_code.is_a? Integer + super(id_or_code) + else + find_by_id_code(id_or_code) + end + end private def add_email_to_mailchimp # Handle any MailChimp errors begin