我正在关注OmniAuth railscasts并尝试使用 authlogic + facebook 而不是如 railscast 中所示的 devise + twitter 来实现相同的功能。
也许我的理解has_many
仍然不好,但在 railscasts ryan 中有以下代码AuthenticationsController
def create
auth = request.env["rack.auth"]
current_user.authentications.find_or_create_by_provider_and_uid(auth['provider'], auth['uid'])
flash[:notice] = "Authentication successful."
redirect_to authentications_url
end
在我的实现中current_user.authentications
返回一个数组[]
我如何调用find_or_create_by_provider_and_uid
一个数组?
我的实施错了吗?不has_many
应该返回一个数组吗?
我得到的错误是我正在调用find_or_create_by_provider_and_uid
一个nil
对象。
current_user.authentications
很好,因为用户还没有任何身份验证。