def create
omniauth = request.env["omniauth.auth"]
authentication = Authentication.find_by_provider_and_uid(omniauth['provider'], omniauth['uid'])
if authentication
flash[:notice] = "Signed in successfully"
sign_in_and_redirect(:user, authentication.user)
elsif current_user
current_user.authentication.create!(:provider => omniauth['provider'], :uid => omniauth['uid'])
flash[:notice] = "Authentication successful"
redirect_to authentication_url
else
user = User.new
user.authentications.build(:provider => omniauth['provider'], :uid => omniauth['uid'])
user.save!
flash[:notice] = "Authentication successful"
sign_in_and_redirect(:user, user)
end
end
这是用于创建 twitter 身份验证的代码。然而,在第 13 行,
user.authentications.build(:provider => omniauth['provider'], :uid => omniauth['uid'])
user.save!
引发错误。
destroy is defined by Active Record
我在网上没有找到任何帮助。我正在关注 railscast 236。Rails 版本 4.0.0,ruby 版本 2。任何帮助将不胜感激。