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

有帮助吗?

解决方案

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?

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top