omn​​iauth与authlogic问题与认证方法

时间:2012-03-18 18:36:48

标签: ruby-on-rails ruby-on-rails-3 facebook-graph-api authlogic omniauth

我一直在关注本教程: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

1 个答案:

答案 0 :(得分:0)

您需要添加此

class User < ActiveRecord::Base
  has_many :authentications

另请注意     omn​​iauth [ 'USER_INFO'] [ '电子邮件'] 变成     omn​​iauth [ '信息'] [ '电子邮件']