2013-05-15 3 views
0

내 Rails 앱에서 사용자 및 인증 데이터를 처리하기위한 테이블이 userauthorization입니다.권한 부여 후 Omniauth 콜백 처리

NoMethodError at /users/auth/twitter/callback 
undefined method `authorizations' for #<Class:0xbdc8100> 

어느 쪽에서, 내가 잘못 가서 어떻게 않았다 나는 트위터로 리디렉션하지만 내 응용 프로그램에 반환 한 후,이 같은 오류를 제공, 가입 트위터를 사용하기 위해 고안 및 Omniauth 모두를 설정 이 문제가 해결 되었습니까? 여기

되어 관련 부품 : omniauth_callbacks_controller.rb :

class OmniauthCallbacksController < Devise::OmniauthCallbacksController 
    def all 
     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 do |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 and :omniauthable 
    devise :database_authenticatable, :registerable, 
    :recoverable, :rememberable, :trackable, :validatable, :omniauthable, :omniauth_providers => [:twitter, :facebook] 

# Setup accessible (or protected) attributes for your model 
    attr_accessible :email, :password, :password_confirmation, :remember_me, :name 
# attr_accessible :title, :body 

    has_many :authorizations, dependent: :destroy 

end 
+0

User.authorizations.from_auth 대신 Authorization.from_auth를 사용해야한다고 생각합니다. –

+0

이전에 'Authorization.from_auth'을 시도했지만 작동하지 않았습니다. – ekremkaraca

답변

1

문제는 ...이 라인에

user = User.authorizations.from_auth (auth_hash)

사용자 클래스에 대한 권한을 호출하지만 사용자 클래스 (예 : 특정 사용자)의 인스턴스에서 속성을 호출해야합니다.

+0

알았어, 문제를 알려주지 만 고칠 필요가있어. – ekremkaraca