Pergunta

I'm implementing a password login to a site that has only oAuth login. The User has a relation to a Facebook_account model where it stores facebook data.

I want this relationship to be dependent on value in the User model.

ie. has_one :facebook_account, if: :fb_login?

Is this possible or am I doing something wrong?

Using rails 4.0.4

Thanks

Foi útil?

Solução

Simply do

has_one :facebook_account

You don't have to assign anything to the association, rails are fine with association being nil. In fact, you don't even need this boolean field, as you can simply call user.facebook_account.present?

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top