Class: ActiveRecord::Base

Inherits:
Object
  • Object
show all
Defined in:
lib/e9_crm/rails_extensions.rb

Class Method Summary collapse

Class Method Details

.money_columns(*column_names) ⇒ Object

Basic conversion for “money” columns using the Money class and Rails composed_of



54
55
56
57
58
59
60
61
62
63
# File 'lib/e9_crm/rails_extensions.rb', line 54

def self.money_columns(*column_names)
  column_names.each do |column_name|
    class_eval <<-EVAL
      composed_of :#{column_name},
                  :class_name => 'Money',
                  :mapping => %w(#{column_name} cents),
                  :converter => Proc.new {|v| v.respond_to?(:to_money) ? v.to_money : v }
    EVAL
  end
end