Skip to content

Instantly share code, notes, and snippets.

@speedmax
Created January 15, 2009 09:43
Show Gist options
  • Save speedmax/47343 to your computer and use it in GitHub Desktop.
Save speedmax/47343 to your computer and use it in GitHub Desktop.
class Account < ActiveRecord::Base
belongs_to :owner, :class_name => 'User', :foreign_key => 'user_id'
has_many :users
has_many :transactions
has_many :websites
has_many :campaigns
def display_name
company || full_name || ''
end
def full_name
"#{first_name.capitalize}, #{last_name.capitalize}" if first_name && last_name
end
def withdraw amount
Transaction.create(
:account => self,
:type => 'debit',
:amount => amount,
:success => true
)
self.credit -= amount
self.save
end
def deposit amount
Transaction.create(
:account => self,
:type => 'debit',
:amount => amount,
:success => true
)
self.credit += amount
self.save
end
end
# GET /accounts/new
# GET /accounts/new.xml
def signup
self.class.layout 'sessions'
@account = Account.new
@user = User.new
respond_to do |format|
format.html # new.html.erb
format.xml { render :xml => @account }
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment