Class: StoreCredit

Inherits:
ActiveRecord::Base
  • Object
show all
Defined in:
app/models/store_credit.rb

Overview

Schema Information

Table name: store_credits

id         :integer(4)      not null, primary key
amount     :decimal(8, 2)   default(0.0)
user_id    :integer(4)      not null
created_at :datetime
updated_at :datetime

Instance Method Summary (collapse)

Instance Method Details

- (none) remove_credit(amount_to_remove)

removes amount from object using SQL math

Parameters:

  • amount (Float)

    to remove

Returns:

  • (none)


25
26
27
28
# File 'app/models/store_credit.rb', line 25

def remove_credit(amount_to_remove)
  sql = "UPDATE store_credits SET amount = (amount - #{amount_to_remove.to_f.round_at(2)}) WHERE id = #{self.id}"
  ActiveRecord::Base.connection.execute(sql)
end