Last active
October 4, 2016 01:18
-
-
Save hugoerg56/a681105e7a9cf3dcb563d7ce5c5cb350 to your computer and use it in GitHub Desktop.
Ejemplo
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
class User | |
after_create :create_relation | |
has_one :empresa | |
has_one :la_otra | |
def create_relation | |
kind == "empresa" ? create_empresa_relation : create_la_otra_relation | |
end | |
def create_empresa_relation | |
self.empresa.create(....) | |
end | |
def create_la_otra_relation | |
self.la_otra.create(....) | |
end | |
# esto es para que tengas un nombre comun para acceder al objeto relacionado | |
def mi_relacion | |
kind == "empresa" ? self.empresa : self.la_otra | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment