Created
March 10, 2012 11:45
-
-
Save taybenlor/2011217 to your computer and use it in GitHub Desktop.
Wong likes pie
This file contains hidden or 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
def price | |
return @price if @price | |
@price = Money.new(self.cents || 0, self.some_relationship.currency || Money.default_currency) | |
end | |
def price=(new_price) | |
@price = new_price.to_money | |
self.cents = @price.cents | |
self.some_relationship.currency = @price.currency_as_string | |
end | |
before_save save_relationship_if_currency_changed | |
def save_relationship_if_currency_changed | |
self.some_relationship.save if self.some_relationship.currency_changed? | |
end | |
#beware that saving this model can save the other one, just in case you don't intend to save it | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment