我一直在关注本教程:http://emumair.wordpress.com/2011/03/17/social-network-authentication-with-omniauth-and-authlogic/。我已经完成了所有这些错误:
undefined method `authentications' for #User<User:0x54cd8d8>
它在控制器中失败:app / controllers / authentications_controller.rb:21:在'create'中:
user.authentications.build(:provider => omniauth['provider'], :uid => omniauth['uid'])
我是否需要向用户模型添加关系以进行身份验证?
我的用户模型目前如下所示:
class User < ActiveRecord::Base
acts_as_authentic
def apply_omniauth(omniauth)
self.email = omniauth['user_info']['email']
# Update user info fetching from social network
case omniauth['provider']
when 'facebook'
# fetch extra user info from facebook
when 'twitter'
# fetch extra user info from twitter
end
end
end
我的authentication.rb文件是:
class Authentication < ActiveRecord::Base
belongs_to :user
validates :user_id, :uid, :provider, :presence => true
validates_uniqueness_of :uid, :scope => :provider
end
答案 0 :(得分:0)
您需要添加此
class User < ActiveRecord::Base
has_many :authentications
另请注意 omniauth [ 'USER_INFO'] [ '电子邮件'] 变成 omniauth [ '信息'] [ '电子邮件']