Description

The has_money gem is intended to allow callers to conveniently convert an attribute stored in cents to dollars.

Configuration

  1. Add it to your Gemfile
    • gem 'activerecord-has_money'
  2. Add it to your model
    • has_money :total_budget
  3. Add it to your tests
    • it { should have_money_for(:total_budget) }

Usage

  1. The original attribute is left unmolested
  2. 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
  3. 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.