0

I've been following this tutorial: http://emumair.wordpress.com/2011/03/17/social-network-authentication-with-omniauth-and-authlogic/. I've walked through it all and I'm getting this error:

undefined method `authentications' for #User<User:0x54cd8d8>

Its failing in the controller: app/controllers/authentications_controller.rb:21:in `create':

user.authentications.build(:provider => omniauth['provider'], :uid => omniauth['uid'])

Do I need to add a relationship to the user model for authentications?

My user model currently looks like this:

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

My authentication.rb file is:

class Authentication < ActiveRecord::Base
belongs_to :user
validates :user_id, :uid, :provider, :presence => true
validates_uniqueness_of :uid, :scope => :provider
end
turbo2oh
  • 2,849
  • 6
  • 34
  • 46

1 Answers1

0

You need to add this

class User < ActiveRecord::Base
  has_many :authentications

Also note that omniauth['user_info']['email'] changed to omniauth['info']['email']

Danny
  • 415
  • 4
  • 6