Created
January 15, 2009 09:43
-
-
Save speedmax/47343 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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