Skip to content

Instantly share code, notes, and snippets.

@PeteMichaud
Created June 28, 2012 16:37
Show Gist options
  • Save PeteMichaud/3012382 to your computer and use it in GitHub Desktop.
Save PeteMichaud/3012382 to your computer and use it in GitHub Desktop.
class User < ActiveRecord::Base
# Include default devise modules. Others available are:
# :token_authenticatable, :confirmable,
# :lockable, :timeoutable and :omniauthable
devise :database_authenticatable, :registerable,
:recoverable, :rememberable, :trackable, :validatable
# Setup accessible (or protected) attributes for your model
attr_accessible :first_name, :last_name, :organization, :email, :password, :password_confirmation, :remember_me, :is_admin, :plan
# Some basic validation of name properties
validates_presence_of :first_name, :last_name, :organization
validates_length_of :first_name, :maximum => 50
validates_length_of :last_name, :maximum => 50
validates :plan,:plan => true
# Database Relationships
has_many :lists
has_one :subscription
has_one :plan, :through => :subscription
has_many :affiliates
# First and Last name helper
def fullname
first_name + ' ' + last_name
end
def is_active?
if is_admin?
true
else
!subscription.suspended unless subscription.nil?
end
end
# The distinction between is_active? and is_suspended? is that a user can only be suspended if
# they have a subscription that's somehow gotten turned off. If they are new and have no
# subscription, they are suspended, they just aren't active
def is_suspended?
return false if self.subscription.nil? #this use is not suspended, he has no subscription to be suspended from
self.subscription.suspended
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment