Created
August 20, 2009 17:06
-
-
Save eladmeidar/171202 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 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