I'm trying to get the money-rails gem working, and I'm having problems...
Other similar stackoverflow questions are 6 years old.
Here's the product I have the appropriate columns on:
class Transactions < ActiveRecord::Base
belongs_to :user, optional: true
validates :trans_id, uniqueness: true
monetize :price_cents
end
I've got the gem in my Gemfile, and have run bundle install successfully.
When I create a new item and look at it with pry,
create(vendor:"foo",amount:2.6,trans_id:'123cccc')
id: nil,
vendor: "foo",
amount_cents: 260,
amount_currency: "USD",
trans_id: "123cccc",
tax_cents: 150,
total_cents:410,
- How do I work with it in dollar amounts? I.e. I want to add amount_cents to tax_cents for total_cents. amount 2.60 instead of amount_cents: 260,
- Do I need to add a 'composed_of'?
- Also, why is 'cent's in the naming? I thought it was supposed to be removed as the vague documentation states:
In this case the name of the money attribute is created automagically by removing the _cents suffix from the column name.