1
0
mirror of https://github.com/LaCasemate/fab-manager.git synced 2025-02-17 11:54:22 +01:00

wallet amount convert auto to float

This commit is contained in:
Peng DU 2016-07-05 11:32:06 +02:00
parent cac9e16c17
commit b22bae1d8f

View File

@ -4,6 +4,14 @@ class Wallet < ActiveRecord::Base
validates :user, presence: true
validates_numericality_of :amount, greater_than_or_equal_to: 0
def amount=(amount)
write_attribute(:amount, amount.to_i * 100)
end
def amount
read_attribute(:amount) / 100.0
end
def credit(amount)
if amount.is_a?(Numeric) and amount >= 0
self.amount += amount