Skip to content

Instantly share code, notes, and snippets.

@eladmeidar
Created August 20, 2009 17:06
Show Gist options
  • Save eladmeidar/171202 to your computer and use it in GitHub Desktop.
Save eladmeidar/171202 to your computer and use it in GitHub Desktop.
class Order < AR:Base
has_one :credit_card_payment
has_one :paypal_express_payment
has_one :horse_shoe_payment
validates_presence_of :payment_type, :in => [:credit_card_express, :paypal_express, :horse_shoe]
def payment_proxy
self.send("#{:payment_type.to_s}_payment")
end
# This one is for forms, like nested_attributes_for
def payment_proxy_attributes=(payment_attributes)
self.send("build_#{:payment_type.to_s}", payment_attributes)
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment