Created
November 8, 2008 02:35
-
-
Save zdennis/23012 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Expense < ActiveRecord::Base | |
composed_of :amount, :class_name => "Money", :mapping => [ %w(amount_in_cents cents)], :converter => lambda { |amount| amount.to_money } | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class CreateExpenses < ActiveRecord::Migration | |
def self.up | |
create_table :expenses do |t| | |
t.integer :amount_in_cents | |
t.timestamps | |
end | |
end | |
def self.down | |
drop_table :expenses | |
end | |
end | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# even though amount_in_cents is stored in the database, you access the the amount | |
# by the amount method. | |
expense = Expense.create! :amount => "$5.00" | |
expense.amount | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment