Skip to content

Instantly share code, notes, and snippets.

@taybenlor
Created March 10, 2012 11:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save taybenlor/2011217 to your computer and use it in GitHub Desktop.
Save taybenlor/2011217 to your computer and use it in GitHub Desktop.
Wong likes pie
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