Creating an additional related model with Devise
I've started to implement a new project using Devise, which is pretty fantastic for handling users. However, when a user signs up, they're not just creating a User
model, but also need to create a related Account
model that represents the company. Additional users will also belongs_to
this Account
model.
I can't seem to find a hook for this in Devise, though it seems like a开发者_JAVA百科 pretty common pattern. What's the best practice for this?
I should also mention that there are a couple of fields for the Account
that need to be provided on the sign_up form, so just something like this in the User
model:
after_create :make_sure_account_exists
def make_sure_account_exists
if self.account.nil?
@account = self.create_account({ :company_name => '???' })
end
.. as I'm not sure how to get the company name.
精彩评论