Description
The has_money gem is intended to allow callers to conveniently convert an attribute stored in cents to dollars.
Configuration
- Add it to your
Gemfile
gem 'activerecord-has_money'
- Add it to your model
has_money :total_budget
- Add it to your tests
it { should have_money_for(:total_budget) }
Usage
- The original attribute is left unmolested
- The virtual attribute
total_budget_dollars
is a Money object- +, -, /, * integers or floats to a Money object will yield a casting error
total_budget_dollars.to_f + 100
will work
- Assuming the above example, you can save models with dollar values
Model.new(total_budget_dollars: 100)
- The resulting attribute will be
total_budget 10000
Copyright
Copyright (c) 2012 Adaptly. See LICENSE.txt for further details.