Pregunta

class User
  has_one :super_admin
end

class SuperAdmin
  belongs_to :user
end

How would I create a SuperAdmin instance associating a certain user, from withing the User model?

I'm looking for something like this (in the User model), but it's not working:

def promote_to_super
  self.super_admin.create!
end
¿Fue útil?

Solución

You can use create_association(attributes = {}):

def promote_to_super
  self.create_super_admin
end

See more here.

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top