You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
semmons99 edited this page Sep 12, 2010
·
14 revisions
Use the #composed_of helper to let Active Record deal with embedding the money object in your models. The following example requires a cents and a currency field.
class ProductUnit < ActiveRecord::Base
belongs_to :product
composed_of :price, :class_name => "Money", :mapping => [%w(cents cents), %w(currency currency_as_string)] private
validate :cents_not_zero def cents_not_zero
errors.add("cents", "cannot be zero or less") unless cents > 0
end validates_presence_of :sku, :currency
validates_uniqueness_of :sku
end