ruby on rails - Omniauth callback processing after authorization -


in rails app, have user , authorization tables handle users , auth data. set both devise , omniauth use twitter sign up, redirects twitter, after returning app, gives error like:

nomethoderror @ /users/auth/twitter/callback  undefined method `authorizations' #<class:0xbdc8100> 

in side, did go wrong , how can fix issue?

here related parts: omniauth_callbacks_controller.rb:

class omniauthcallbackscontroller < devise::omniauthcallbackscontroller     def         user = user.authorizations.from_auth(auth_hash)         if user.persisted?             flash.notice = "signed in!"             sign_in_and_redirect user         else             session["devise.user_attributes"] = user.attributes             redirect_to new_user_registration_url         end     end       alias_method :twitter, :all      protected     def auth_hash         request.env['omniauth.auth']     end end 

authorization.rb:

class authorization < activerecord::base      attr_accessible :uid, :provider     belongs_to :user      def self.from_auth(auth)         where(auth.slice(:provider, :uid)).first_or_create |user|         user.provider = auth.provider         user.uid = auth.uid     end end 

user.rb:

class user < activerecord::base # include default devise modules. others available are: # :token_authenticatable, :confirmable, # :lockable, :timeoutable , :omniauthable     devise :database_authenticatable, :registerable,      :recoverable, :rememberable, :trackable, :validatable, :omniauthable, :omniauth_providers => [:twitter, :facebook]  # setup accessible (or protected) attributes model     attr_accessible :email, :password, :password_confirmation, :remember_me, :name # attr_accessible :title, :body      has_many :authorizations, dependent: :destroy  end 

your issue in line...

user = user.authorizations.from_auth(auth_hash)

you call authorizations on class user, attribute needs called on instance of user class, i.e. specific user.


Comments

Popular posts from this blog

Change php variable from jquery value using ajax (same page) -

How can I fetch data from a web server in an android application? -

jquery - How can I dynamically add a browser tab? -